Link to home
Start Free TrialLog in
Avatar of detox1978
detox1978Flag for United Kingdom of Great Britain and Northern Ireland

asked on

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

Avatar of gerodim
gerodim

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

Avatar of detox1978

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of gerodim
gerodim

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
will try this tomorrow.

+i have full use of the server, so can make any changes etc...
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!!!
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
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!!!
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


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
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.
ok thanks. will have a look at the permissions....