.bat文件 - 写一个新的变量到.msl文件(.txt) [英] .bat file - Write a new variable to a .msl (.txt) file
问题描述
OK,所以这是一个后续另一个问题我在前面了。我的code发现了previous工作日,然后通过3和9之间的所有小时分钟的组合循环
OK, so this is a follow-up to another question I had earlier. My code finds the previous business day and then loops through all the hour-minute combinations between 3 and 9.
在code养活这个新变量到.msl(基本上是我们的文档直接服务器.txt文件)。
The code will feed this new variable into a .msl (basically a .txt file for our document direct server).
我需要code写的发现变量到.msl文件并运行该文件。
I need the code to write the found variable into the .msl file and run the file.
下面是我到目前为止有:
Here is what I have so far:
@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'标识
是我需要注入的变量。
我试过在引号和什么不该做这个,不能弄清楚如何正确地注入它。
Where is says VERSIONID ' id
Is where I need to inject the variable.
I've tried to do this in quotes and what not and can't figure out how to inject it properly.
推荐答案
的Windows变量内嵌评估。所有你需要做的就是替换 ** **号
与!ID!
。
Windows variables are evaluated inline. All you have to do is replace **id**
with !id!
.
只是让我觉得我已经做了一些有用的东西,我会帮你previous工作日计算为好。您可以在杂交code和使用一个JScript 日期()
对象以移除呼应出一个临时的.vbs脚本的必要性。我也感动重定向到 test.msl
来一个括号code座,清理code位。如果您的MSL处理程序允许,你可以转储所有的 OPENVIEW ...导出... CLOSE
行到一个文件中,只运行一次的处理程序,这可能会提高效率。看到这个答案的版本2的例子。
Just so I feel like I've done something useful, I'll help you with that previous business day calculation as well. You can hybridize the code and use a JScript Date()
object to remove the necessity of echoing out to a temporary .vbs script. I also moved the redirect to test.msl
to a parenthetical code block to clean up the code a bit. If your MSL handler allows, you can dump all your OPENVIEW...EXPORT...CLOSE
lines to a file and only run the handler once, which might improve efficiency. See revision 2 of this answer for an example.
我觉得这你想要做什么。使用.bat扩展名保存。
I think this does what you want. Save it with a .bat extension.
@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(''));
这篇关于.bat文件 - 写一个新的变量到.msl文件(.txt)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!