Jump to content


Photo

shell_exec() question


  • Please log in to reply
2 replies to this topic

#1 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 16 June 2006 - 08:24 PM

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.

// This is the code
$cmdline = $server_exe.' -k stop';
$rslt = shell_exec ($cmdline);
print_r($GLOBALS);
echo '<HR>Result<HR>'.$rslt;

This is the result that I get from print_r($_GLOBALS);
    [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] => 

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


Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 18 June 2006 - 07:29 PM

Have you tried using exec() or system() ?

#3 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 21 June 2006 - 12:16 AM

Yes I tried exec() later and it works now

Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users