View previous topic :: View next topic |
Author |
Message |
RTAdams89 -
Joined: 06 Nov 2005 Posts: 102
|
Posted: Wed Oct 10, 2007 5:52 pm Post subject: Calling "net start" from PHP |
|
|
I have a PHP web page which shows various system info of the server it is served from. I have several windows command line outputs stored as variables with the PHP commands:
Code: |
$ipconfig = `ipconfig -all`;
exec("netstat -n", $connections);
$services= `net start`;
$drivers= `drivers`;
|
Later, I can display these variables on the page. All of them work except for the $services one. When I try t display $services, I just get a blank line. The same issue occurs for and "net" command output I try to store as a variable. Why is this?[/code] |
|
Back to top |
|
|
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Mon Oct 22, 2007 5:09 pm Post subject: Re: Calling "net start" from PHP |
|
|
RTAdams89 wrote: | When I try t display $services, I just get a blank line. The same issue occurs for and "net" command output I try to store as a variable. Why is this?[/code] |
That's probably because these commands do not output the results to the standard output (where PHP expects them) but rather tries to display them on a terminal window (which is hidden). _________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
|
RTAdams89 -
Joined: 06 Nov 2005 Posts: 102
|
Posted: Mon Oct 22, 2007 5:43 pm Post subject: |
|
|
How would I fix this? Other commands such as "ipconfig" or "netstat" work. |
|
Back to top |
|
|
pkSML -
Joined: 29 May 2006 Posts: 952 Location: Michigan, USA
|
Posted: Tue Oct 23, 2007 11:15 pm Post subject: |
|
|
Code: | <?php
exec('net start', $services);
print_r($services);
?> |
_________________ Stephen
Need a LitlURL?
http://CodeBin.yi.org |
|
Back to top |
|
|
RTAdams89 -
Joined: 06 Nov 2005 Posts: 102
|
Posted: Wed Oct 24, 2007 6:21 pm Post subject: |
|
|
Using that code I get the output:
|
|
Back to top |
|
|
pkSML -
Joined: 29 May 2006 Posts: 952 Location: Michigan, USA
|
Posted: Wed Oct 24, 2007 9:17 pm Post subject: |
|
|
Hmmm... It worked just fine for me.
Check the command line and see if it's outputting anything. _________________ Stephen
Need a LitlURL?
http://CodeBin.yi.org |
|
Back to top |
|
|
RTAdams89 -
Joined: 06 Nov 2005 Posts: 102
|
Posted: Thu Oct 25, 2007 12:09 am Post subject: |
|
|
It works on the command line, but i get that weird array output when trying it in php. |
|
Back to top |
|
|
pkSML -
Joined: 29 May 2006 Posts: 952 Location: Michigan, USA
|
Posted: Thu Oct 25, 2007 2:28 am Post subject: |
|
|
I think safe mode would disable the exec funtion. You might check that in your php.ini file. _________________ Stephen
Need a LitlURL?
http://CodeBin.yi.org |
|
Back to top |
|
|
RTAdams89 -
Joined: 06 Nov 2005 Posts: 102
|
Posted: Thu Oct 25, 2007 3:41 am Post subject: |
|
|
Safe mode is off. If I run the following PHP code:
Code: | <?php
exec('net start > c:\test.txt');
?>
|
I get an empty "test.txt" on my C drive. If i run that command (net stat > test.txt) from the local command line, I get info in the file as expected.
Is there perhaps a Windows security setting that is preventing Abyss/PHP from using the "net" commands. |
|
Back to top |
|
|
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Fri Oct 26, 2007 1:40 pm Post subject: |
|
|
RTAdams89 wrote: | Is there perhaps a Windows security setting that is preventing Abyss/PHP from using the "net" commands. |
The Windows command line redirection did not work too (hence the empty file you got) so it is not something specific to Abyss/PHP. Your command is not outputting any data to the standard output.
What is your Windows version? _________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
|
RTAdams89 -
Joined: 06 Nov 2005 Posts: 102
|
Posted: Fri Oct 26, 2007 5:48 pm Post subject: |
|
|
The command line output does work. If I run "CMD" and type
Code: | net start > c:\test.txt |
I get a file filled with a list of running Services.
However, if in a PHP file I type
Code: | <?php
exec('net start > c:\test.txt');
?> |
I get an empty file on the drive. |
|
Back to top |
|
|
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
|
Back to top |
|
|
pkSML -
Joined: 29 May 2006 Posts: 952 Location: Michigan, USA
|
Posted: Tue Nov 13, 2007 10:09 pm Post subject: |
|
|
You might also try the passthru(). It works like exec(), but doesn't do any tampering with the output. _________________ Stephen
Need a LitlURL?
http://CodeBin.yi.org |
|
Back to top |
|
|
RTAdams89 -
Joined: 06 Nov 2005 Posts: 102
|
|
Back to top |
|
|
pkSML -
Joined: 29 May 2006 Posts: 952 Location: Michigan, USA
|
Posted: Wed Nov 14, 2007 9:56 pm Post subject: |
|
|
aprelium wrote: | What is your Windows version? |
I'm guessing you're running Win2000 or XP Pro. I think I read somewhere that PHP runs on username "system", rather than the username that's logged in. That may just be for *nix OS's, but it seems that might be your issue.
Also, what is your PHP version? _________________ Stephen
Need a LitlURL?
http://CodeBin.yi.org |
|
Back to top |
|
|
RTAdams89 -
Joined: 06 Nov 2005 Posts: 102
|
Posted: Thu Nov 15, 2007 2:33 am Post subject: |
|
|
Abyss should be running as the user I am logged in on as that is the user I installed it from. The only other user on the system is the default "administrator" account, and even running from there, it should work. |
|
Back to top |
|
|
|