[英]Windows Task Scheduler job with parameter and STDOUT redirect
我有一个命令行程序,它不需要参数或一个参数。 如果没有提供参数,它会用简单的代码提示输入参数,例如:
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 重定向到一个文件时,它会启动、运行并且永远不会完成。 如果我手动运行该作业(通过右键单击并从 Task Scheduler 运行),它会弹出一个控制台窗口,其中显示Please provide the Parameter
。
我的问题是:如果我将 STDOUT 重定向到文件,为什么 Windows 任务计划程序作业会短路我传递给程序的参数?
输出重定向可能会也可能不会与 Windows 任务计划程序一起使用。 解决方法是在批处理文件中运行所需的命令(包括输出重定向),并从任务计划程序调用批处理文件。
script.bat
----------
myprogram SomeValue > results.log
答案是什么? 我也有同样的问题。 我有一个脚本,该脚本需要任务计划程序中的参数。 任务计划程序的“操作”选项卡>“程序/脚本:cmd”。 添加参数> cmd python.exe脚本参数>输出文件> 2&1。 Havent运气不错。 有谁知道该怎么做??? 提前致谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.