• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 11474
  • Last Modified:

Execute command line code from a php file

I'm trying to execute command line code via a php file, but am having problem.  anybody any thoughts on where i might be going wrong?

here's my code
____________________________________________________________________________________

<?php
$command = 'iisweb /create c:\Inetpub\wwwroot\MyTest \"My Test 2\" /d www.MyTest2.com';
$output = passthru("$command");
echo(nl2br($output));
?>
_____________________________________________________________________________________


it's odd because it works if i change the command to DIR.... but NET VIEW doesnt work....


any suggestions?

Many thanks in Adv.

D

0
detox1978
Asked:
detox1978
  • 6
  • 5
1 Solution
 
gerodimCommented:
use the shell_exec command
e.g.
$output = shell_exec('iisweb /create c:\Inetpub\wwwroot\MyTest \"My Test 2\" /d www.MyTest2.com');

you can also check out this link : www.php.net/exec

0
 
detox1978Author Commented:
Thanks for the suggestion, but i've already tried it and it returns a blank page....


I think it may be a setting or security feature you have to enable, because the script below returns a blank page....

<?php
$command = 'Net view';
$output = shell_exec("$command");
echo(nl2br($output));
?>


but this returns the output ....

<?php
$command = 'dir';
$output = shell_exec("$command");
echo(nl2br($output));
?>


any thoughts?

D
0
 
gerodimCommented:
yeah, your server doesn't recognise the windows folders.

perhaps this is what you're looking for:

<?php
$command = '%windir%\system32\net view';
$output = shell_exec("$command");
echo(nl2br($output));
?>


btw you have to wait a little for the net view to give output... CU!
(P.S. please if that's the answer grade me with A cause i need the points in order to keep my Premium Services)
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
detox1978Author Commented:
will try this tomorrow.

+i have full use of the server, so can make any changes etc...
0
 
gerodimCommented:
If it's not too much trouble and the answer is the one you seek could you accept the answer in April (3 days from now)??? thanx!!!
0
 
detox1978Author Commented:
The code you gave returns a blank page, so i made a slight change to see if it was executing it

<?php
$command = '%windir%\system32\cmd /C net view >> C:\Inetpub\wwwroot\helloworld.txt';
$output = shell_exec("$command");
echo(nl2br($output));
?>

this creates the file helloworld.txt, but leave it empty.

any thoughts
0
 
gerodimCommented:
try to open a command promt swich to your windows\system32 folder and try executing net view from there... also try to find witch folder net.exe is in and write the absolute path in the $command string... Post back!!!
0
 
detox1978Author Commented:
My fault the iis browser account didn't have permissions to execute the net.exe , i have change this and it now work.  So i guess i just need to give the correct permission to the iisweb,

any thought on who i give access and to which files.

From searching my hard drive there is a iisweb.vsb file


0
 
detox1978Author Commented:
Ok, now i'm sure we've nearly cracked this.  The net view problem was a permissions issue.

This is the code i am running, but it just seems to hang

<?php
$command = 'iisweb /create c:\Inetpub\wwwroot\MyTest "My Test 4" /d www.MyTest2.com';
$output = shell_exec("$command");
echo(nl2br($output));
?>


Any thoughts on what needs changing?

Thanks again for your time.

D
0
 
gerodimCommented:
I don't use IIS so i can't be that helpful... However the syntax is correct so i guess the command is the problem.
0
 
detox1978Author Commented:
ok thanks. will have a look at the permissions....
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now