Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带有参数和标准输出重定向的Windows任务计划程序作业_C#_Windows_Scheduled Tasks - Fatal编程技术网

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