C# 带有参数和标准输出重定向的Windows任务计划程序作业
我有一个命令行程序,它不需要任何参数或一个参数。如果未提供任何参数,则会提示输入参数,代码如下:C# 带有参数和标准输出重定向的Windows任务计划程序作业,c#,windows,scheduled-tasks,C#,Windows,Scheduled Tasks,我有一个命令行程序,它不需要任何参数或一个参数。如果未提供任何参数,则会提示输入参数,代码如下: String theParameter = String.Empty; if (args.Length == 1) theParameter = args[0]; else { Console.Write("Please provide theParameter: "); theParameter = Console.ReadLine(); } Console.WriteLine("
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
或
或
一切按预期进行
类似地,当我将Windows 7任务调度器与myprogram SomeValue
一起使用时,它会按预期启动、执行和完成
但是,当我使用myprogram SomeValue>results.log
将STDOUT重定向到一个文件时,它会启动、运行并且永远不会完成。如果我手动运行作业(通过右键单击并从任务计划程序运行),它会弹出一个控制台窗口,其中包含,请提供参数
我的问题是:如果我将STDOUT重定向到一个文件,为什么Windows任务调度器作业会使传递给程序的参数短路?输出重定向。解决方法是在批处理文件中运行所需的命令(包括输出重定向),并从任务调度器调用批处理文件
script.bat
----------
myprogram SomeValue > results.log
> myprogram SomeValue > results.log
{Some Output in the results.log file)
script.bat
----------
myprogram SomeValue > results.log