1

谁能帮我编写我想要的批处理文件?

我有一个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 次(感觉很蠢)。希望我已经说清楚了。那么有人可以帮助我吗?提前致谢!!!我已经在其他地方发布了相同的问题,但尚未得到答案。

4

1 回答 1

2

只要您的 exe 程序从标准输入中获取输入,您就可以通过管道将响应传递给程序。无需使用 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 命令非常灵活。

于 2013-01-19T15:17:15.550 回答