PHP, exec(), perl, not output

Yesterday in writing some PHP to put a pretty web based front end on a perl script I ran into a problem, no output was being returned from the perl script.

I tried all the PHP commands for calling external commands ( exec(), system(), passthru(), and shell_exec() ) and all failed to return output.

What was VERY frustrating was that I was effectively reusing some code that called a different perl script and returned output without any problems. All my various google searches were fruitless as none of them provided me with any solutions or ideas as to how to solve my problem. So I was left to my own devices to figure things out.

Ater much trial and error I discovered that if I displayed the script’s help text (which exits immediately after that) the exec call worked as expected. That lead me to the root cause of my problem. When I was using this script straight from the command like I opened a log file and appended some information to it as the script executed. Perhaps that was the cause….. Not wanting to loose that functionality I first explicitly made sure all my output was being directed to STDOUT. That did not help. Next I removed all instances to printing to the logfile. That also didn’t help. It was only when I removed the open() statement that the erl script began returning information to PHP as I expected.

Comments are closed.