これをもう一度試してみましょう。これは、私があなたが望むと思うことを行うバッチコードです。
@echo off
call myApp.exe %*
set result=%errorlevel%
echo result = %result%
if %result%==0 call myApp.exe close (or whatever the paramaters are)
if %result%==1 echo "Message explaining what error code 1 means"
if %result%==2 echo "Message explaining what error code 2 means"
...
これにより、バッチ ファイルに渡したパラメーターを使用して myApp.exe が呼び出されます。%*
必要に応じて、ハードコードされた入力に置き換えることができます。これにより、アプリケーションの終了コードが出力され、再度呼び出して閉じるか、エラー コードを説明するメッセージを出力できます。
MSDNから変更
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "externalExecutable.exe";
p.Arguments = "-arg1 -arg2";
p.Start();
// Wait for the child process to exit before
// reading to the end of its redirected stream.
p.WaitForExit();
// Read the output stream
string output = p.StandardOutput.ReadToEnd();
// Parse the output to see what you should do
// Or just use the exit code from the proccess
if (output.Equals("0") || p.ExitCode == 0) {
// Do what you need to in this case
} else {
// Do something else here
}