Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.