5

コマンドを別のコマンドライン プログラムに送信する方法はありますか?

私は特別なコマンドライン プログラムを持っていますが、次のような構文を使用してコマンドを送信することはできません。program.exe something_to_do

プログラムは次のように実行します: (「ここの構文」は、テキストを入力し、入力して開始する場所です)

TheWhateverCommandLineProgram
Version 1.1
Give an option: "here syntax"

コード内のプログラムは次のようになります。

echo TheWhateverCommandLineProgram
echo Version 1.1
Set opt=
set /p opt=Give an option: 
if %opt%==command1 goto com1
if %opt%==command2 goto com2
...

まあ、それを作ったのは私ではなかったと思います(ところで:もちろん、TheWhateverCommandLineProgramとは呼ばれていません)

4

3 に答える 3

6

コマンドラインプログラムにキーボード入力を与えたいだけなら、それを使用echoしてパイプするだけです:

echo some text | program.exe

さらに行が必要な場合は、それらをファイルに書き込み、入力リダイレクトを使用します。

echo one line > file
echo second line >> file
program.exe < file
于 2009-08-18T16:27:12.070 に答える
1

I'm not 100% sure I understand what you're looking for. Here's two options:

  1. You have two windows, each running a batch program. Let's say they are called myscript1.bat and myscript2.bat. You want to send a set of commands from myscript1.bat to be executed by myscript2.bat

  2. You have a single batch script named myscript.bat, which executes a single program named program.exe. You want program.exe to execute some commands, or do some something.

Are either of these what you're looking for? Here's some idea:

  1. Make myscript1.bat create a third file, mycommands.bat. Once myscript2.bat sees the file mycommands.bat exists, it will execute it and delete it. (Wow. Lame.)

  2. Use Windows Scripting Host command (it's built in to Windows since Win2K) or Powershell (usually on most computers nowadays, if they have been updated). Either of these can send keystrokes to another program. Using those keystrokes, you can control the other program.

于 2009-07-29T08:35:56.457 に答える
0

他のプログラムはどのような形式で入力を受け取りますか? コマンドプロンプトから?

後者の場合、Autohotkey をお勧めします: http://www.autohotkey.com/

Autohotkey をブリッジとして使用すると、コマンドがキー押下として他のバッチ ファイルのウィンドウに送信されます。

フォーラムで助けを求めることができます。彼らは非常に役に立ちます。

于 2009-07-29T08:34:16.273 に答える