Calling "net start" from PHP

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
RTAdams89
-


Joined: 06 Nov 2005
Posts: 102

PostPosted: Wed Oct 10, 2007 5:52 pm    Post subject: Calling "net start" from PHP Reply with quote

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 View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Mon Oct 22, 2007 5:09 pm    Post subject: Re: Calling "net start" from PHP Reply with quote

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 View user's profile Send private message Send e-mail
RTAdams89
-


Joined: 06 Nov 2005
Posts: 102

PostPosted: Mon Oct 22, 2007 5:43 pm    Post subject: Reply with quote

How would I fix this? Other commands such as "ipconfig" or "netstat" work.
Back to top View user's profile Send private message
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Tue Oct 23, 2007 11:15 pm    Post subject: Reply with quote

Code:
<?php
exec('net start', $services);
print_r($services);
?>

_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
RTAdams89
-


Joined: 06 Nov 2005
Posts: 102

PostPosted: Wed Oct 24, 2007 6:21 pm    Post subject: Reply with quote

Using that code I get the output:
Code:
Array
(
)

Back to top View user's profile Send private message
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Wed Oct 24, 2007 9:17 pm    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
RTAdams89
-


Joined: 06 Nov 2005
Posts: 102

PostPosted: Thu Oct 25, 2007 12:09 am    Post subject: Reply with quote

It works on the command line, but i get that weird array output when trying it in php.
Back to top View user's profile Send private message
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Thu Oct 25, 2007 2:28 am    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
RTAdams89
-


Joined: 06 Nov 2005
Posts: 102

PostPosted: Thu Oct 25, 2007 3:41 am    Post subject: Reply with quote

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 View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Fri Oct 26, 2007 1:40 pm    Post subject: Reply with quote

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 View user's profile Send private message Send e-mail
RTAdams89
-


Joined: 06 Nov 2005
Posts: 102

PostPosted: Fri Oct 26, 2007 5:48 pm    Post subject: Reply with quote

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 View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Tue Nov 13, 2007 3:15 pm    Post subject: Reply with quote

RTAdams89,

That's really a weird behavior.

We suggest that you try the function listed in http://www.php.net/manual/en/function.exec.php#57538 as it may help getting the output of command lines on Windows.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Tue Nov 13, 2007 10:09 pm    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
RTAdams89
-


Joined: 06 Nov 2005
Posts: 102

PostPosted: Wed Nov 14, 2007 5:02 pm    Post subject: Reply with quote

If I use "system()" or "passthru()" it returns "2". That's right, the number two. If I try to use that other function @ http://www.php.net/manual/en/function.exec.php#57538, I get no output.
Back to top View user's profile Send private message
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Wed Nov 14, 2007 9:56 pm    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
RTAdams89
-


Joined: 06 Nov 2005
Posts: 102

PostPosted: Thu Nov 15, 2007 2:33 am    Post subject: Reply with quote

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 View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group