Windows 批处理文件-如何在多个实例中从它们输出信息
是否可以通过多个输出从批处理文件输出信息 例如 然后20秒后创建一个新文件Windows 批处理文件-如何在多个实例中从它们输出信息,windows,batch-file,Windows,Batch File,是否可以通过多个输出从批处理文件输出信息 例如 然后20秒后创建一个新文件 test.bat > output2.txt 等(流程仍在运行)无需仅因为您仅限于批处理而放弃。这是很容易做到的 @ECHO off :: Check if the script has ran before, and set the iteration IF EXIST next.txt ( FOR /F "tokens=1" %I in (next.txt) DO SET /A _result=%I+1>
test.bat > output2.txt
等(流程仍在运行)无需仅因为您仅限于批处理而放弃。这是很容易做到的
@ECHO off
:: Check if the script has ran before, and set the iteration
IF EXIST next.txt (
FOR /F "tokens=1" %I in (next.txt) DO SET /A _result=%I+1> next.txt
) else (
SET /A _result=^1> next.txt
)
:: Now the iteration is stored in a variable named %_result%
echo test > output%_result%.txt
如果您下载了一份针对windows的sed,要获得一个具有时间顺序的唯一名称应该不会太难
time /t | sed "s/:/_/g" | sed "s/ /_/">>time.txt
for /F "tokens=*" %%I IN (time.txt) DO echo test >> output-%%I.txt
注意:如果您使用的是Win Vista/7,则需要将其更改为%I,而不是%%I非常难以实现。一种方法是创建文件,用于指示有多少实例正在运行。但一般来说,我会说,您应该尝试接受NT脚本的限制,并转向另一种选择。这是一个编写了超过40kib的广泛使用的NT脚本的人的回答。最简单的答案可能是否定的,但是如果你能给我们更多关于你要做什么的上下文,也许我们能给你一个更好的答案。
%I
语法是直接在命令提示符下使用的,%%I
一个用于批处理脚本。在所有NTs(包括Vista/7)中的工作方式都相同。
time /t | sed "s/:/_/g" | sed "s/ /_/">>time.txt
for /F "tokens=*" %%I IN (time.txt) DO echo test >> output-%%I.txt