Redirect output from a command in a batch file whose output is already redirected?

I searched high and low, but all the suggestions and tips I found did not work for some reason. I have a batch file that is called as such:

cmd /C "automateMyProgram.bat >> automation.log 2>>&1" 

This works fine: automation.log loads with all stdout and stderr for this particular batch file. However, in this batch of script, I have the following command:

 start php updateDB.php param1 param2 ^> updateDB.log 

The PHP script runs just fine and reads fine in the parameters, but updateDB.log is never created. I made sure that the php error message in the php.ini file is configured to output errors to the command line interface. There are several echo expressions in the php script that I need to write to the log, but for some reason they are not output. I read that if you use the start command to invoke a program, you must use the carriage operator to redirect the output, since the program starts 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 this did not work from the batch file, but it happened when I copied and pasted it directly into the CMD window on the desktop.

Can any of you know how I can redirect the output of a php script that is being called from a batch file?

Thanks for your time and help!

+3
windows scripting php batch-file
source share
2 answers

This is probably the easiest 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" 
+5
source share

Here is an example of code that worked in a BATCH file that starts VBScripts with the START command. It will execute a separate process and put the results in 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^" 
0
source share

All Articles