Page 2 of 2

Posted: Mon Apr 17, 2006 12:27 pm
by sheepz
i can't seem to exec simple windows shell commands. i'm using XPsp2, IIS6, PHP5. can't seem to get any of these functions working: `backtick` system() exec() shell_exec()

Code: Select all

<?php

echo shell_exec(`%computername%`);
echo exec(`%computername%`);
echo system(`C:\WINDOWS\system32\cmd.exe %computername%`); 

$result = `ping.exe 127.0.0.1`;
echo "$result";

?>
i dont get any errors but i dont get any results either. all i get is a blank screen? How do i give PHP access to shell commands?

Posted: Mon Apr 17, 2006 12:28 pm
by feyd
You're executing two commands per line.

a backtick string is an alias to running system()

Check your error logs.

Posted: Mon Apr 17, 2006 12:31 pm
by feyd
Some further examples:

Code: Select all

[feyd@home]>php -r "echo `echo %computername%`;"
FEYD

[feyd@home]>php -r "echo `echo %date%`;"
Mon 04/17/2006

[feyd@home]>php -r "echo `echo %time%`;"
12:30:30.45

Posted: Mon Apr 17, 2006 9:01 pm
by sheepz
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i can't seem to execute cmd commands.  i must be doing it wrong. using backticks, shell_exec(), exec(), system() and no luck

Code: Select all

<?php

echo shell_exec(`%computername%`);
echo exec(`%computername%`);
echo system(`C:\WINDOWS\system32\cmd.exe %computername%`);

$result = `ping.exe 127.0.0.1`;
echo "$result";

?>
i dont any errors but i dont get any results either. i just get a blank screen. =T how do i check if my php is actually processing the shell commands?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Apr 17, 2006 9:06 pm
by feyd
you haven't changed a thing in that script since you last post. Carefully examine the examples I posted. Compare these examples against your code.

Posted: Tue Apr 18, 2006 1:02 pm
by sheepz
feyd, i'm so sorry, there must have been a mistake becuase both posts are almost identical. i was having posting problems. when i posted the first time i didn't see my post and must have reposted again. i'm definitely going compare codes, thanks for the help. =)

Posted: Tue Apr 18, 2006 1:16 pm
by sheepz
i have this for testing

Code: Select all

<?php

echo `echo %computername%`;

?>
and i'm getting this error =T

Warning: shell_exec() [function.shell-exec]: Unable to execute 'echo %computername%' in c:\Inetpub\wwwroot\shell.php on line 10

Posted: Wed Apr 19, 2006 7:23 pm
by sheepz
i tried putting this into my cmd console

php -r "echo `echo %date%`;"

but i get a 'php' is not a recognized command. i know this is a stupid question but would this be preventing my php from executing shell commands?

Posted: Wed Apr 19, 2006 7:31 pm
by Ambush Commander
No. That means that the PHP executable is not in your path. Try navigating to the bin folder in your PHP installation directory and attempting, or adding that directory to your path (alternatively, you can drop a bat file in your WINDOWS directory with the contents along the line of C:\path\to\php.exe %*)