?
Solved

Execute command line code from a php file

Posted on 2005-03-23
11
Medium Priority
?
11,440 Views
Last Modified: 2011-08-18
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
Comment
Question by:detox1978
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 3

Expert Comment

by:gerodim
ID: 13626844
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
 
LVL 2

Author Comment

by:detox1978
ID: 13629800
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
 
LVL 3

Accepted Solution

by:
gerodim earned 2000 total points
ID: 13635761
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:detox1978
ID: 13643373
will try this tomorrow.

+i have full use of the server, so can make any changes etc...
0
 
LVL 3

Expert Comment

by:gerodim
ID: 13645123
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
 
LVL 2

Author Comment

by:detox1978
ID: 13653067
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
 
LVL 3

Expert Comment

by:gerodim
ID: 13657707
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
 
LVL 2

Author Comment

by:detox1978
ID: 13663554
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
 
LVL 2

Author Comment

by:detox1978
ID: 13664561
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
 
LVL 3

Expert Comment

by:gerodim
ID: 13667081
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
 
LVL 2

Author Comment

by:detox1978
ID: 13670900
ok thanks. will have a look at the permissions....
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question