パラメータなしまたは 1 つのパラメータを必要とするコマンド ライン プログラムがあります。パラメーターが指定されていない場合、次のような単純なコードでパラメーターを要求します。
String theParameter = String.Empty;
if (args.Length == 1) theParameter = args[0];
else {
Console.Write("Please provide theParameter: ");
theParameter = Console.ReadLine();
}
Console.WriteLine("Some Output");
インタラクティブに期待どおりに動作します。
> myprogram
Please provide theParameter:
{a value provided}
Some Output
また
> myprogram SomeValue
Some Output
また
> myprogram SomeValue > results.log
{Some Output in the results.log file)
すべてが期待どおりに機能します。
同様に、Windows 7 タスク スケジューラを使用myprogram SomeValue
すると、期待どおりに起動、実行、完了します。
ただし、myprogram SomeValue > results.log
STDOUTをファイルにリダイレクトするために使用すると、ファイルが起動して実行され、完了しません。ジョブを手動で実行すると (タスク スケジューラから右クリックして実行)、コンソール ウィンドウにPlease provide the Parameter
.
私の質問は次のとおりです: STDOUT をファイルにリダイレクトすると、Windows タスク スケジューラ ジョブがプログラムに渡されるパラメーターをショートサーキットするのはなぜですか?