有人可以帮我编写我想要的批处理文件吗?
我有一个exe文件。双击它后,会弹出一个黑色的DOS窗口,询问“文本文件的名称”。我必须输入带扩展名的全名。按下回车后,在同一个黑色DOS窗口中又出现了一个问题,例如“文件中有多少列?1。10列; 2. 100列:3。150列。此后,exe文件会询问更多类似的问题。
我想让exe处理一些输入文本文件,只有输入文件的名称和数据不同,但实际上列数和行数等都是一样的。
所以我想也许一个批处理文件可以在批处理模式下运行这个exe(回答提升的问题)。
bat文件中的代码可能如下所示:
@echo off
:: Let the exe run and process file1
start C:\Batexe\myprogram.exe
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?
:: Let the exe run and process file2
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?
:: Could anyone help with the code to answer following up questions automatically (no need to even display the questions)?
:: Let the exe run and process file3
.
.
.
我可能有100个文本输入文件。上面的代码块我可能会重复100次(感觉很愚蠢)。希望我已经清楚了。那么有人可以帮助我吗?提前致谢!!!我在其他地方发布了相同的问题但尚未得到答案。
答案 0 :(得分:2)
只要你的exe程序从stdin获取输入,你就可以将响应传递给程序。没有必要使用START。
echo Response | yourProgram.exe
您可以使用括号轻松管道一系列回复
(
echo Response 1
echo Response 2
echo Response 3
) | yourProgram.exe
您说只有第一个响应更改 - 文件名。您可能应该使用某种形式的FOR循环来迭代您的文件名。我举几个例子。
如果要处理特定目录中的所有.TXT文件:
@echo off
for %%F in ("pathToYourFolder\*.txt") do (
echo %%F
echo ConstantColumnCount
echo ConstantRowCount
echo etc.
) | yourProgram.exe
如果要明确列出批处理文件中的文件:
@echo off
for %%F in (
file1.txt
optionalPath1\file2.txt
file3.txt
etc.
) do (
echo %%F
echo ConstantColumnCount
echo ConstantRowCount
echo etc.
) | yourProgram.exe
如果列出要在名为FileList.txt的文件中处理的所有文件,则每行一个文件:
@echo off
for /f "eol=: delims=" %%F in (FileList.txt) do (
echo %%F
echo ConstantColumnCount
echo ConstantRowCount
echo etc.
) | yourProgram.exe
还有更多可能性 - FOR命令非常灵活。