5

我有一个命令行程序,它不需要参数或一个参数。如果没有提供参数,它会使用简单的代码提示输入参数,例如:

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 任务计划程序作业会短路我的参数被传递给程序?

4

1 回答 1

2

输出重定向可能会也可能不会与 Windows 任务计划程序一起使用。解决方法是在批处理文件中运行所需的命令(包括输出重定向),并从任务计划程序调用批处理文件。

script.bat
----------
myprogram SomeValue > results.log
于 2018-07-19T13:07:40.647 回答