1

必要なバッチ ファイルのコーディングを手伝ってくれる人はいますか?

私は1つのexeファイルを持っています。それをダブルクリックすると、黒い DOS ウィンドウがポップアップし、「テキスト ファイルの名前」を尋ねられます。拡張子を付けてフルネームを入力する必要があります。Enter キーを押した後、同じ黒い DOS ウィンドウで、「ファイルの列数は? 1. 10 列; 2. 100 列: 3. 150 列」のような別の質問が続きました。その後、exe ファイルはさらにいくつかの質問をします。同様の質問。

いくつかの入力テキストファイルをexeに処理させたいのですが、入力ファイルの名前とデータが違うだけで、実際には列数や行数などはすべて同じです。

そのため、バッチ ファイルでこの exe を (昇格された質問に答えて) バッチ モードで実行できるのではないかと考えました。

バット ファイルのコードは次のようになります。

@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プログラムが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という名前のファイルにリストする場合、1行に1つのファイル:

@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 に答える