gpt4 book ai didi

batch-file - Windows Batch - 将程序输出重定向到 for 循环中的文件

转载 作者:行者123 更新时间:2023-12-04 22:41:20 26 4
gpt4 key购买 nike

我使用的是 Windows 7。

我有一个名为 optAlg.exe 的程序,我在批处理脚本的 for 循环中调用它,我想重定向 optAlg.exe 的输出到 %outputFile%。当我在批处理脚本中运行以下循环时,optAlg.exe 的输出被写入控制台。

for %%i in (data/5Node/*.dat) do @(
set inputFile=%%i
set outputFile="%inputFile%.out"
optAlg %inputFile% 500 ^> %outputFile%
)

我怎样才能让它输出到文件而不是控制台?

编辑:我想做的是让它调用

optAlg 1.dat 500 > 1.dat.out
optAlg 2.dat 500 > 2.dat.out
...
optAlg n.dat 500 > n.dat.out

我的 .dat 文件被命名为 1.datn.dat

最佳答案

您需要使用 setlocal enabledelayedexpansion 和关联的 !var! 语法。

setlocal enabledelayedexpansion
for %%i in (data/5Node/*.dat) do (
set inputFile=%%i
set outputFile="!inputFile!.out"
optAlg "!inputFile!" 500 > !outputFile!
)

关于batch-file - Windows Batch - 将程序输出重定向到 for 循环中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18501343/

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