重定向输出已重定向的批处理文件中命令的输出?
我到处搜索,但我发现的所有建议和技巧由于某种原因都不起作用。我有一个这样调用的批处理文件:
cmd /C "automateMyProgram.bat >> automation.log 2>>&1"
效果很好:automation.log 加载了该特定批处理文件的所有 stdout 和 stderr。但是,在该批处理脚本中,我有以下命令:
start php updateDB.php param1 param2 ^> updateDB.log
php 脚本确实执行得很好,并且读取了参数也很好,但 updateDB.log 从未创建。我确保 php.ini 文件中的 php 错误报告设置为将错误输出到命令行界面。我需要将 php 脚本中的几个 echo 语句记录到日志中,但由于某种原因它们没有被输出。我读到,如果您使用 start 命令来调用程序,则必须使用脱字符号运算符来重定向输出,因为程序是在新进程中启动的。我也尝试过:
start php updateDB.php param1 param2 >> updateDB.log
但这也不起作用。所以我然后尝试:
start /B "Database Update" "php" "param1" "param2" >> updateDB.log
这在批处理文件中不起作用,但当我将其直接复制并粘贴到桌面上的cmd窗口中时,它就起作用了。
你们中有人知道如何重定向从批处理文件调用的 php 脚本的输出吗?
感谢您的时间和帮助!
I've searched high and low, but all the suggestions and tips I've found do not work for some reason. I have a batch file that is being invoked as such:
cmd /C "automateMyProgram.bat >> automation.log 2>>&1"
That works great: automation.log gets loaded with all the stdout and stderr for that particular batch file. However, within that batch script I have the following command:
start php updateDB.php param1 param2 ^> updateDB.log
The php script does get executed just fine and reads in the parameters just fine, but updateDB.log is never created. I ensured that php error reporting in the php.ini file is set to output errors to the command line interface. There are several echo statements within the php script that I need to have recorded to a log, but they are not being output for some reason. I read that if you use the start command to invoke a program, you must use the caret operator to redirect output since the program is started in a new process. I also tried:
start php updateDB.php param1 param2 >> updateDB.log
and that didn't work either. So I then tried:
start /B "Database Update" "php" "param1" "param2" >> updateDB.log
and that didn't work from within the batch file, but it did when I copy and pasted it directly into a cmd window on the desktop.
Might any of you know how I can redirect the output of the php script being called from a batch file?
Thanks for your time and help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是最简单的解决方案:
或者,如果您想在 updateDB.log 中包含错误消息,
This is probably the simplest solution:
or, if you want to include error messages in updateDB.log,
以下是在 BATCH 文件中使用 START 命令启动 VBScript 的代码示例。它将启动单独的进程并将结果放入指定的日志文件中。
Here is a sample of code that worked in a BATCH file launching VBScripts with the START command. It will lauch the seperate process and put the results into the specified log file.