3

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!

2 Answers 2

5

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"
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the elegant solution!
+1 I also had problem with redirecting output, e.g. start app.exe param > log 2>&1. Your solution works, thanks!
0

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^"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.