重定向输出已重定向的批处理文件中命令的输出?

发布于 2025-01-08 07:58:28 字数 837 浏览 0 评论 0原文

我到处搜索,但我发现的所有建议和技巧由于某种原因都不起作用。我有一个这样调用的批处理文件:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无声无音无过去 2025-01-15 07:58:28

这可能是最简单的解决方案:

start cmd /c "php updateDB.php param1 param2 > updateDB.log"

或者,如果您想在 updateDB.log 中包含错误消息,

start cmd /c "php updateDB.php param1 param2 > updateDB.log 2>&1"

This is probably the simplest solution:

start cmd /c "php updateDB.php param1 param2 > updateDB.log"

or, if you want to include error messages in updateDB.log,

start cmd /c "php updateDB.php param1 param2 > updateDB.log 2>&1"
终遇你 2025-01-15 07:58:28

以下是在 BATCH 文件中使用 START 命令启动 VBScript 的代码示例。它将启动单独的进程并将结果放入指定的日志文件中。

rem **Setting the passed device to run against to a varible**
SET Audit_Device=%1

rem     **Launching "_SomeScript.vbs" in a seperate window**
start "WindowTitle" /d%~dp0  cmd /C cscript.exe ^"%~dp0_SomeScript.vbs^" %Audit_Device% ^>^"%~dp0%Audit_Device%_SomeScriptLogFile.txt^"

rem       **Launching "ListPermissionsForAllShares-Basic-and-Detailed.vbs" in a seperate window**
start "List Share Permission" /d%~dp0  cmd /C cscript.exe ^"%~dp0ListPermissionsForAllShares-Basic-and-Detailed.vbs^" %Audit_Device% ^>^"%~dp0%Audit_Device%_Share_Permissions.txt^"

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.

rem **Setting the passed device to run against to a varible**
SET Audit_Device=%1

rem     **Launching "_SomeScript.vbs" in a seperate window**
start "WindowTitle" /d%~dp0  cmd /C cscript.exe ^"%~dp0_SomeScript.vbs^" %Audit_Device% ^>^"%~dp0%Audit_Device%_SomeScriptLogFile.txt^"

rem       **Launching "ListPermissionsForAllShares-Basic-and-Detailed.vbs" in a seperate window**
start "List Share Permission" /d%~dp0  cmd /C cscript.exe ^"%~dp0ListPermissionsForAllShares-Basic-and-Detailed.vbs^" %Audit_Device% ^>^"%~dp0%Audit_Device%_Share_Permissions.txt^"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文