Click to See Complete Forum and Search --> : command line doesnt run with exec


Anon
02-10-2001, 03:52 PM
I'm trying to execute a command line such as Ping on Win2000SP1 running PHP404pl1 with IIS

When I run the script from command line, ie:

c:\php>php test.php

everything works fine and I get the results whether I'm using exec() or system() but if I'm running the script through the web server it seems like the script to run the command line is ignored.

What am I doing wrong?

TIA,

Jay

Anon
02-11-2001, 04:23 PM
Win32 opens a new Virtual Machine when performing exec()/system() in the PHP script, so no results are returned to the calling Virtual Machine, but PHP will wait seemingly forever for them. I had this a few months ago and gave up, opting to write the code purely in PHP.
Other things to check is the path you use, as you can specify '/' paths, you must use '\\' paths
e.g. exec("d:\\scripts\\xyz");
e.g. exec("del \"images\\$pic\"");

Jay wrote:
-------------------------------
I'm trying to execute a command line such as Ping on Win2000SP1 running PHP404pl1 with IIS
When I run the script from command line, ie:
c:\php>php test.php
everything works fine and I get the results whether I'm using exec() or system() but if I'm running the script through the web server it seems like the script to run the command line is ignored.

What am I doing wrong?

TIA,

Jay

Anon
02-12-2001, 01:06 PM
Thanks for replying to my message. I tried escaping the slashes (\\) in the folder path but it didn't seem to do any good either.

All I'm trying to do is publish ping results to the webpage. I thought it would be as simple as:

<? system("ping yahoo.com") ?>

but it doesn't work, although it does if I run the script from command line:

c:\php4>php test_ping.php

Any ideas?

TIA,

Jay

Anon
02-12-2001, 01:28 PM
The ping prob. is working, but the results usually won't be passed back due to the Virtual Machines. So, you could try

<?php
system("ping yahoo.com > c:\\ya.txt");
$ya = fopen("c:\\ya.txt", "r");
while (!feof ($ya)) {
$buffer = fgets($ya, 1024);
print "$buffer<BR>";
}
fclose ($ya);
?>

A bit of a round-about way, but does what it should. If it hangs during processing (as mine used to) then try:
system("cmd /c ping yahoo.com > c:\\ya.txt");

Anon
02-12-2001, 02:08 PM
That did the trick. Thanks a lot :)


Jay

pmullins
04-08-2001, 10:39 AM
CJD wrote:
-------------------------------
The ping prob. is working, but the results usually won't be passed back due to the Virtual Machines. So, you could try

<?php
system("ping yahoo.com > c:\\ya.txt");
$ya = fopen("c:\\ya.txt", "r");
while (!feof ($ya)) {
$buffer = fgets($ya, 1024);
print "$buffer";
}
fclose ($ya);
?>

A bit of a round-about way, but does what it should. If it hangs during processing (as mine used to) then try:
system("cmd /c ping yahoo.com > c:\\ya.txt");

When I try this I get the following error:

Warning: Unable to fork [ping yahoo.com > c:\ya.txt] in D:\webpages\php\ping.php on line 2

I get the same error whenever I try to run any external program.

Anon
01-24-2002, 02:31 AM
I have that same problem, let me know if you find a solution

Carsten Winsnes