Re: Capturing shell command output.
| From: | Wouter van Vliet / Interpotential | Date: | Sat, 18 Aug 2007 21:17:37 +0000 |
| Subject: | Re: Capturing shell command output. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-261002@lists.php.net to get a copy of this message | ||
You may want to look into shell_exec, which executes a command and returns
the output. If you're accepting arguments from user input, don't forget
proper use of escapeshellcmd and escapeshellarg ;-).
Something else that might cause your commands from failing, is that the
utilities are not inside apache's PATH - trying to call them by there
absolute filename can help out. Have you inspected your error_log? There
often tends to be a lot of useful stuff in there.
Good luck!
Wouter
On 18/08/07, shiplu <shiplu.net@gmail.com> wrote:
>
> HI,
> I am working on a PHP project that interacts with command line utilities.
> My php is running by apache. Means I am not running any php CLI.
>
> here is the function that I am using for capturing command output.
>
> function run_command($comamnd){
> $ret=
$command 1> COMMAND.OUT 2>1;
> $contents=get_file_contents("COMMAND.OUT");
> return $contents;
> }
>
> The function does not work. If I use any shell command like ls, cat,
> echo, set. it works.
> But If I use any utility like, mpg321, cd-info. It does not work. It
> outputs a blank string.
> I used system(), passthru() with both "2&>1" and "2>1". But no
> out put.
> All the time, its blank.
> Even I used a shell script "run.sh"
> run.sh contents:
> =====================================
> #!/bin/sh
> sh COMMAND 1> COMMAND.OUT 2&>1
> cat COMMAND.OUT
> echo 0 > COMMAND
> =====================================
>
> I called this script by this function
> function run_command($command){
> $h=fopen("COMMAND","w");
> fwrite($h,$command);
> fclose($h);
> ob_start();
> passthru("./run.sh");
> $ret = ob_get_contents();
> ob_end_clean();
> return $ret;
> }
>
> and by this.
>
> function run_command($command){
> $h=fopen("COMMAND","w");
> fwrite($h,$command);
> fclose($h);
> return system("./run.sh");
> }
>
> Please help me. or show me some way.
>
>
> --
> shout at http://shiplu.awardspace.com/
>
> Available for Hire/Contract/Full Time
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Interpotential.com
Phone: +31615397471