我有一个命令行程序,它要求没有参数或一个参数。如果没有提供参数,它会使用简单的代码提示参数:
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)
所有工作都按预期进行。
类似地,当我使用带有myprogram SomeValue
的Windows 7任务计划程序时,它会按预期启动,执行和完成。
但是,当我使用myprogram SomeValue > results.log
将STDOUT重定向到文件时,它会启动,运行并永远不会完成。如果我手动运行作业(通过右键单击并从任务计划程序运行),它会抛出一个带有Please provide the Parameter
的控制台窗口。
我的问题是:如果我将STDOUT重定向到文件,为什么Windows任务计划程序作业会将我的参数短路传递给程序?
答案 0 :(得分:0)
输出重定向may or may not work with the Windows Task Scheduler。解决方法是在批处理文件中运行所需的命令(包括输出重定向),然后从“任务计划程序”中调用该批处理文件。
script.bat
----------
myprogram SomeValue > results.log