gpt4 book ai didi

batch-file - .bat 文件 - 将新变量写入 .msl (.txt) 文件

转载 作者:行者123 更新时间:2023-12-01 20:05:34 25 4
gpt4 key购买 nike

好的,这是 another question I had earlier 的后续内容。我的代码查找前一个工作日,然后循环遍历 3 到 9 之间的所有小时-分钟组合。

代码会将这个新变量输入到 .msl(基本上是我们的文档直接服务器的 .txt 文件)中。

我需要代码将找到的变量写入 .msl 文件并运行该文件。

这是我到目前为止所拥有的:

@ECHO off

setlocal enabledelayedexpansion
echo wd = Weekday^(Date^(^), vbSunday^)>yesterday.vbs
echo if wd ^< 3 then dif = -1 - wd else dif = -1 >>yesterday.vbs
echo d = dateadd^("d", dif, Date^(^)^)>>yesterday.vbs
echo wscript.echo DatePart^("yyyy",d^) ^& " " ^& DatePart^("m", d^) ^& " " ^& DatePart^("d", d^) >>yesterday.vbs
for /f "tokens=1-3" %%I in ('cscript /nologo yesterday.vbs') do (
set year=%%I
if %%J leq 9 (set month=0%%J) else set month=%%J
if %%K leq 9 (set day=0%%K) else set day=%%K
)
del yesterday.vbs
set YYYY=%year:~-4%
set MM=%month:~-2%
set DD=%day:~-2%

set prevbusday=%YYYY%%MM%%DD%

echo %prevbusday%

pause

For /L %%G IN (3,1,9) DO (
For /L %%H IN (0,1,59) DO (
set "h=0%%H"
ECHO %prevbusday%0%%G!h:~-2!
set "id=%prevbusday%0%%G!h:~-2!"
break>test.msl
(echo OPENVIEW SERVERID 'Mobius Server ' REPORTID 'TrialReports ' VERSIONID ' **id** 'SECTIONID ' 0000-000 Name of Report' PAGE 1)> test.msl
(echo EXPORT ASCII FILE 'C:\New folder\check.rpt' CURSEC GROUP '') >> test.msl

(echo CLOSE) >> test.msl
rem **Here I will add the code to call the newly minted 'test.msl' - but
rem I'll get to that later**

)
)

pause

哪里说VERSIONID ' id 是我需要注入(inject)变量的地方。我尝试过在引号中执行此操作,但不知道如何正确注入(inject)它。

最佳答案

Windows 变量是内联计算的。您所要做的就是将 **id** 替换为 !id!

为了让我觉得我做了一些有用的事情,我也会帮助您计算前一个工作日。您可以混合代码并使用 JScript Date() 对象来消除回显到临时 .vbs 脚本的必要性。我还将对 test.msl 的重定向移至括号中的代码块,以稍微清理一下代码。如果您的 MSL 处理程序允许,您可以将所有 OPENVIEW...EXPORT...CLOSE 行转储到文件中,并且仅运行处理程序一次,这可能会提高效率。请参阅revision 2 of this answer举个例子。

我认为这符合你的要求。使用 .bat 扩展名保存它。

@if (@CodeSection == @Batch) @then

@ECHO off
setlocal enabledelayedexpansion

for /f %%I in ('cscript /nologo /e:JScript "%~f0"') do set "prevbusday=%%I"

echo %prevbusday%
pause

For /L %%G IN (3,1,9) DO (
For /L %%H IN (0,1,59) DO (
set "h=0%%H"
set "id=%prevbusday%0%%G!h:~-2!"
echo !id!

>test.msl (
echo OPENVIEW SERVERID 'Mobius Server ' REPORTID 'TrialReports ' VERSIONID ' !id! ' SECTIONID ' 0000-000 Name of Report' PAGE 1
echo EXPORT ASCII FILE 'C:\New folder\check.rpt' CURSEC GROUP ''
echo CLOSE
)

rem **Here I will add the code to call the newly minted 'test.msl' - but
rem I'll get to that later**

)
)

pause

goto :EOF
@end // end batch / begin JScript chimera

var day = 1000 * 60 * 60 * 24,
yesterday = new Date().getDay() - 1,
prevbusday = new Date(!yesterday?new Date()-day*3:(yesterday<0?new Date()-day*2:new Date()-day)),
y = [
prevbusday.getFullYear(),
('0' + (prevbusday.getMonth() + 1)).match(/\d\d$/)[0],
('0' + prevbusday.getDate()).match(/\d\d$/)[0]
]

WSH.Echo(y.join(''));

关于batch-file - .bat 文件 - 将新变量写入 .msl (.txt) 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30173423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com