detox1978
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
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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
will try this tomorrow.
+i have full use of the server, so can make any changes etc...
+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!!!
ASKER
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\hellowo rld.txt';
$output = shell_exec("$command");
echo(nl2br($output));
?>
this creates the file helloworld.txt, but leave it empty.
any thoughts
<?php
$command = '%windir%\system32\cmd /C net view >> C:\Inetpub\wwwroot\hellowo
$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!!!
ASKER
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
any thought on who i give access and to which files.
From searching my hard drive there is a iisweb.vsb file
ASKER
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
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.
ASKER
ok thanks. will have a look at the permissions....
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