我有一个命令行程序,它不需要参数或一个参数。如果没有提供参数,它会使用简单的代码提示输入参数,例如:
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 任务计划程序作业会短路我的参数被传递给程序?