Jump to content

shell commands in PHP?


sheepz

Recommended Posts

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

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

i had to leave off the terminator for almost all the lines [b];[/b] or else this forum wont let me post
[code]
<?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";

?>
[/code]

i dont any errors but i dont get any results either. i just get a blank screen. =T any ideas?
Link to comment
https://forums.phpfreaks.com/topic/7674-shell-commands-in-php/
Share on other sites

Tested on my WinXP development machine and working
[code]<?php
exec("ping 192.168.1.1",$result)
echo "<pre>";
print_r($result);
echo "</pre>";
?>[/code]
Output:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Array
(
[0] =>
[1] => Pinging 192.168.1.1 with 32 bytes of data:
[2] =>
[3] => Reply from 192.168.1.1: bytes=32 time=1ms TTL=255
[4] => Reply from 192.168.1.1: bytes=32 time=1ms TTL=255
[5] => Reply from 192.168.1.1: bytes=32 time=1ms TTL=255
[6] => Reply from 192.168.1.1: bytes=32 time=1ms TTL=255
[7] =>
[8] => Ping statistics for 192.168.1.1:
[9] => Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
[10] => Approximate round trip times in milli-seconds:
[11] => Minimum = 1ms, Maximum = 1ms, Average = 1ms
)[/quote]

[b]EDIT:[/b] I also had to exclude the semi-colon from my exec() line, server would not allow it - forbidden message.
Link to comment
https://forums.phpfreaks.com/topic/7674-shell-commands-in-php/#findComment-28146
Share on other sites

[!--quoteo(post=365987:date=Apr 18 2006, 06:20 AM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Apr 18 2006, 06:20 AM) [snapback]365987[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Tested on my WinXP development machine and working
[code]<?php
exec("ping 127.0.0.1",$result)
echo "<pre>";
print_r($result);
echo "</pre>";
?>[/code]
Output:

[b]EDIT:[/b] I also had to exclude the semi-colon from my exec() line, server would not allow it - forbidden message.
[/quote]


sorry for the late response been really hectic at work and totally forgot =( thanks for the help =)
i copied the code exactly and added the ; to the end of the exec() line. i'm still getting a

Warning: exec() [function.exec]: Unable to fork [ping 127.0.0.1] in c:\Inetpub\wwwroot\shell.php on line 11

Array
(
)

do i need to setup my php.ini or have my computer allow php to access shell commands?
Link to comment
https://forums.phpfreaks.com/topic/7674-shell-commands-in-php/#findComment-30167
Share on other sites

You shouldn't have to change any settings for this to work - Mine is set-up pretty much default. Maybe you are running an older version of PHP4? Searching for "Unable to fork" on Google turns up quite a few resources on the error - Maybe you could solve it better then?

Or maybe try out the system() command instead of exec() - You should just be able to swap the word exec for system, they both except the same paramiters.
Link to comment
https://forums.phpfreaks.com/topic/7674-shell-commands-in-php/#findComment-30243
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.