dptr1988 Posted June 16, 2006 Share Posted June 16, 2006 I'm trying to make a PHP script that will restart my Apache webserver. But when I use shell_exec() it doesn't return any results. And Apache prints the help message and says 'apache.exe: illegal option -- k' Is the '-' character something special, like the backslash, in PHP? The PHP manual says that shell_exec() returns a string, but the string was empty and the output was the the main error log of Apache. Can a program that you call with shell_exec() redirect it's output somewhere else?Here is the code that I'm using. Note that there is a space between the shell_exec and the brackets (). Thats because phpfreaks.com tells me '403 forrbidden You don't have permission to access /forums/index.php on this server.' if I don't have that space there.[code]// This is the code$cmdline = $server_exe.' -k stop';$rslt = shell_exec ($cmdline);print_r($GLOBALS);echo '<HR>Result<HR>'.$rslt;[/code]This is the result that I get from print_r($_GLOBALS);[code] [include_file] => C:\FTB\dptr1988.mooo.com\htdocs\local\sample.conf [apache_dir] => C:/Program Files/Apache Group/Apache2/conf/ [current_file] => C:/Program Files/Apache Group/Apache2/conf/dptr1988.mooo.com.conf [server_exe] => "C:/Program Files/Apache Group/Apache2/bin/apache.exe" [cmdline] => "C:/Program Files/Apache Group/Apache2/bin/apache.exe" -k restart [rslt] => [/code]The command line works when I enter it in the command prompt, so it's a good command line.Is there a better way to run programs instead of using shell_exec()?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/12190-shell_exec-question/ Share on other sites More sharing options...
zq29 Posted June 18, 2006 Share Posted June 18, 2006 Have you tried using exec() or system() ? Quote Link to comment https://forums.phpfreaks.com/topic/12190-shell_exec-question/#findComment-47070 Share on other sites More sharing options...
dptr1988 Posted June 21, 2006 Author Share Posted June 21, 2006 Yes I tried exec() later and it works now Quote Link to comment https://forums.phpfreaks.com/topic/12190-shell_exec-question/#findComment-47852 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.