jaymc Posted June 23, 2008 Share Posted June 23, 2008 I am running a php script via the command line, for example php -f script.php However, it is forcefully outputting the return of the command, without me echoin it etc Here is script content <? $command = "/usr/sbin/apachectl configtest"; $result = shell_exec($command); ?> I want $result to contain the output from the $command, at the moment, it does not and the output from the command is forcefully dumped In the manual, it is meant to output the return to the given VAR. This is not working. I have tried system, exec, passthru They all do the same Any idea why? Quote Link to comment https://forums.phpfreaks.com/topic/111464-solved-system-command-dump/ Share on other sites More sharing options...
trq Posted June 23, 2008 Share Posted June 23, 2008 <?php $command = "/usr/sbin/apachectl configtest 1>/dev/null"; $result = shell_exec($command); ?> Quote Link to comment https://forums.phpfreaks.com/topic/111464-solved-system-command-dump/#findComment-572114 Share on other sites More sharing options...
jaymc Posted June 23, 2008 Author Share Posted June 23, 2008 Did not work, it still outputs it without an echo, and, $result does not contain the return or any value Quote Link to comment https://forums.phpfreaks.com/topic/111464-solved-system-command-dump/#findComment-572118 Share on other sites More sharing options...
trq Posted June 23, 2008 Share Posted June 23, 2008 What does the output look like? Maybe you need to redirect stderr and stdout. <?php $command = "/usr/sbin/apachectl configtest &> /dev/null"; $result = shell_exec($command); ?> Quote Link to comment https://forums.phpfreaks.com/topic/111464-solved-system-command-dump/#findComment-572120 Share on other sites More sharing options...
jaymc Posted June 23, 2008 Author Share Posted June 23, 2008 That stopped it from forcefully outputting, but did not send the output to the VAR <? $command = "/usr/sbin/apachectl configtest &> /dev/null"; passthru($command, $result); echo $result; ?> The output of $result was "0", not sure why as the reuslt of the command is "Syntax OK" Any more ideas? Quote Link to comment https://forums.phpfreaks.com/topic/111464-solved-system-command-dump/#findComment-572122 Share on other sites More sharing options...
trq Posted June 23, 2008 Share Posted June 23, 2008 You might try using exec() instead. Quote Link to comment https://forums.phpfreaks.com/topic/111464-solved-system-command-dump/#findComment-572125 Share on other sites More sharing options...
jaymc Posted June 23, 2008 Author Share Posted June 23, 2008 None of them work.. tried them all. I could use ob_start(); but Im not running it in a browser to flush the raw output to a VAR Command line based Quote Link to comment https://forums.phpfreaks.com/topic/111464-solved-system-command-dump/#findComment-572133 Share on other sites More sharing options...
jaymc Posted June 24, 2008 Author Share Posted June 24, 2008 Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/111464-solved-system-command-dump/#findComment-573050 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.