Page 1 of 2

Execute commands on the server?

Posted: Sun May 28, 2006 10:43 pm
by toasty2
How can I execute commands on my Windows (XP x64 edition) Server. I was hoping to be able to run programs and maybe even stop them on my server. Like, for a remote management type thing..
How do I do this?
Thanks for any input you kind people may have.

Posted: Mon May 29, 2006 4:04 am
by Chris Corbyn
Backtick syntax:

Code: Select all

echo `dir`;
Aslo: exec(), system(), popen(), proc_open()

Posted: Mon May 29, 2006 10:16 am
by toasty2
So, exec can be used for launching command line programs or batch files, but Can it open a program with a GUI, like Notepad or Firefox?

Posted: Mon May 29, 2006 10:37 am
by Ambush Commander
Well, then it would launch the program on the server, but not on your client machine. In short, no.

Posted: Mon May 29, 2006 10:48 am
by toasty2
Heh, i'm not stupid...I meant the Server machine lol.

Posted: Mon May 29, 2006 10:49 am
by Ambush Commander
Yes. It would work. The PHP script, however, would hang until the program shut itself back off.

Posted: Mon May 29, 2006 10:51 am
by toasty2
How can I get it to completly not care about the program after it starts it?

Posted: Mon May 29, 2006 10:52 am
by Ambush Commander
Well, if you were on Unix, I would have pointed you to pcntl_fork, but to be blunt, at this point, PHP isn't the best language for this sort of task.

Posted: Mon May 29, 2006 10:54 am
by toasty2
What happens if it "hangs"?
I was thinking of something liek this to run commands specified in a form submitted:

Code: Select all

<?php
exec ( $stuff );
?>

Posted: Mon May 29, 2006 10:55 am
by Ambush Commander
Well, the way PHP works, when you execute shell commands, it waits for the command to finish.

For GUIs, that means that as long as the screen is up, PHP will wait for the process to terminate.

Perhaps "hang" isn't the best word to describe it.

Posted: Mon May 29, 2006 11:36 am
by toasty2

Code: Select all

<?php
exec("C:\Documents and Settings\Administrator\Desktop\winlister.exe");
?>
It doesnt do anything.

Posted: Mon May 29, 2006 11:44 am
by Ambush Commander
Double-escape the backslashes: "\\"

Posted: Mon May 29, 2006 11:46 am
by toasty2
It doesnt work, it isnt starting the program.

Code: Select all

<?php
exec("C:\\Documents and Settings\\Administrator\\Desktop\\winlister.exe");
?>

Posted: Mon May 29, 2006 11:50 am
by Chris Corbyn
exec() isn't made for running GUI based applications. It just reads the response from STDOUT. Don;t use PHP for something like this - it's all kinds of wrong ;)

Posted: Mon May 29, 2006 11:54 am
by toasty2
Could I tell php to run a batch file and have the batch file run a GUI based program?