Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 以txt作为参数的批处理文件中有多个exe_Batch File - Fatal编程技术网

Batch file 以txt作为参数的批处理文件中有多个exe

Batch file 以txt作为参数的批处理文件中有多个exe,batch-file,Batch File,我有一个txt文件,每行有一个文本,这个文本必须通过使用-p传递给一个exe文件,该文件创建了一个新文件,文件名由-f给出 test1.exe -p line1 -f line1.config 然后将配置文件作为参数传递,如下所示 test2.exe line1.config line1.bin 我正试图使用windows批处理自动化这个过程,因为我想实现 file.txt line1 line2 line3 line4 诸如此类 test1.exe -p line1 -f line1.c

我有一个txt文件,每行有一个文本,这个文本必须通过使用-p传递给一个exe文件,该文件创建了一个新文件,文件名由-f给出

test1.exe -p line1 -f line1.config
然后将配置文件作为参数传递,如下所示

test2.exe line1.config line1.bin
我正试图使用windows批处理自动化这个过程,因为我想实现

file.txt

line1
line2
line3
line4
诸如此类

test1.exe -p line1 -f line1.config
test1.exe -p line2 -f line2.config
test1.exe -p line3 -f line3.config
test1.exe -p line4 -f line4.config
test2.exe line1.config line1.bin
test2.exe line2.config line2.bin
test2.exe line3.config line3.bin
test2.exe line4.config line4.bin
del line1.config
del line2.config
del line3.config
del line4.config
你能给我一个建议吗

解决方案:

@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in ('type file.txt') do (
    test1.exe -p %%a -f %%a.config
    test2.exe %%a.config %%a.bin
    del %%a.config
)

假设您希望配置的名称大致命名为'line1.config'等(而不是以行的实际内容命名),您可以执行以下操作:

@echo off

set line=0
for /F "delims=" %%a in (file.txt) do call :exec "%%a"
exit /B 0

:exec
set /A line=%line%+1
echo test1.exe -p %1 -f line%line%.config
echo test2.exe line%line%.config line%line%.bin
echo del line%line%.config
exit /B 0

如果您愿意执行实际操作,请删除“echo”。

阅读
的输出以获取/?
如何执行?我在(file.txt)DO test1.exe-p%%a-F%%a.config test2.exe%%a.config%%a.bin中尝试了/F%%a,但是我弄错了,看起来不错。请记住:
%%a
是批处理文件语法。如果您直接在命令行上执行此操作,请仅使用
%a
。请不要将您的解决方案放入问题中。而是创建一个答案并接受它。
@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in ('type file.txt') do (
    test1.exe -p %%a -f %%a.config
    test2.exe %%a.config %%a.bin
    del %%a.config
)