我有一个命令行程序,不需要参数或需要一个参数。如果没有提供参数,它会使用简单的代码提示输入参数,例如:
String theParameter = String.Empty;
if (args.Length == 1) theParameter = args[0];
else {
Console.Write("Please provide theParameter: ");
theParameter = Console.ReadLine();
}
Console.WriteLine("Some Output");
Run Code Online (Sandbox Code Playgroud)
交互式地它按预期工作:
> myprogram
Please provide theParameter:
{a value provided}
Some Output
Run Code Online (Sandbox Code Playgroud)
或者
> myprogram SomeValue
Some Output
Run Code Online (Sandbox Code Playgroud)
或者
> myprogram SomeValue > results.log
{Some Output in the results.log file)
Run Code Online (Sandbox Code Playgroud)
一切都按预期进行。
同样,当我使用 Windows 7 任务计划程序时,myprogram SomeValue它会按预期启动、执行和完成。
但是,当我使用myprogram SomeValue > results.log将 STDOUT 重定向到文件时,它会启动、运行并且永远不会完成。如果我手动运行该作业(通过右键单击并从任务计划程序运行),它会弹出一个带有Please provide the Parameter.
我的问题是:如果我将 STDOUT 重定向到文件,为什么 Windows 任务计划程序作业会短路我传递给程序的参数?