This blog has moved!

If you are not automatically redirected to the new address, please direct your browser to
http://www.juxtaservices.com/blog/
and update your bookmarks.

Tuesday, May 08, 2007

Dump stderr to stdout

I recently discovered the solution to a previously baffling problem I was having with the code deployment tool I have been writing as part of my thesis research. By the way, Doba has graciously allowed me to open source the entire project. You can find it here.

Since the project relies on the execution of SVN commands through the use of the exec() function in PHP to perform actions dictated through the web interface, there are alot of exec() calls made in the performance of duty. The output of these commands is generally captured so that it can be displayed back to the user and logged into the system. I was previously baffled however, why sometimes when an SVN error occurred, that it was not returned as output for the function call, but would instead be written to the Apache error log. That was until, upon discussing the issue with a coworker that we stumbled upon the reason. The SVN client was writing the error to stderr instead of stdout! Hello!

In order to solve the error therefore, and thereby prevent myself from having to mow through a bunch of error logs when something failed, I simply had to make sure and pipe stderr to stdout for any svn commands being executed. Here's what I appended to the end of the command to make it happen:

svncommand 2>&1

Since all of the SVN commands are executed through a central function, adding this pipe for all commands was a cinch. Now any and all errors encountered are properly displayed with the SVN output.

0 Comments:

Post a Comment

<< Home