Jump to content

shell_exec() question


dptr1988

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/12190-shell_exec-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.