For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > December 2006 > php exec();









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author php exec();
Sam

2006-12-11, 7:01 pm

hi,

i've been trying to create a php script that writes some text to a
file, then runs the perl interpreter on the file and shows the output.
it works ok when valid perl is written to the file, so if i use 'print
"hello world";' then it outputs 'hello world'. the problem is, if i
enter invalid perl code, such as 'blahblahblah;', it outputs nothing.
i'd like the php script to be able to get the error/output. does anyone
know of a way to do this?

thanks in advance.

ZeldorBlat

2006-12-11, 7:01 pm


Sam wrote:
> hi,
>
> i've been trying to create a php script that writes some text to a
> file, then runs the perl interpreter on the file and shows the output.
> it works ok when valid perl is written to the file, so if i use 'print
> "hello world";' then it outputs 'hello world'. the problem is, if i
> enter invalid perl code, such as 'blahblahblah;', it outputs nothing.
> i'd like the php script to be able to get the error/output. does anyone
> know of a way to do this?
>
> thanks in advance.


exec() only captures the contents of stdout, not stderr. When you send
invalid code to your perl interpreter, the errors are likely coming
back on stderr.

One solution would be to redirect stderr to stdout on the fly:

$command = 'ls';
exec($command . ' 2>&1', $out);

Another (more complicated) solution is to use proc_open() and set up
pipes to read from stdout and stderr.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com