...

View Full Version : PHP Script To Run Windows Commandline



blackfish
01-04-2008, 12:33 PM
Hi All,

Could someone please point me in the direction of making a PHP web script process a Windows commandline either directly or running a batch file..?

The scenario is this:

I have a file directory of ISO images for my network. I have Daemon tools installed on my network server which runs a WAMP Server. What i want to happen is to produce a webpage so that you can select the image you require from a drop down menu. Then when you click some sort of mount button on the webpage, the PHP script either directly or through an MSDOS batch file mounts the images to Daemon tools depending on what image you have selected.

Many Thanks,

Blackfish

tonyyeb
01-04-2008, 02:39 PM
I think you might want to start looking here:

http://uk2.php.net/manual/en/function.exec.php

EDIT: Here is an example I found. It works but you may need to change the permissions on c:\windows\system32\cmd.exe to allow the Internet Guest Account read/execute perms.



<?php
$data = array(); // define array

$cmd = "c:/test.bat";
exec($cmd, $data, $ret); // execute command, output is array


echo "<pre>";
if ($ret == 0)
{ // check status code. if successful
foreach ($data as $line)
{ // process array line by line
echo "$line\n";
}
}
else
{
echo "Error in command"; // if unsuccessful display error
}
echo "</pre>";
?>


Now all you need to do is see if Daemon tools has command line support.

blackfish
01-04-2008, 02:46 PM
I think you might want to start looking here:

http://uk2.php.net/manual/en/function.exec.php

I did take a look at this but didn't find it very helpful unfortunately

arnyinc
01-04-2008, 02:54 PM
I'm going to have to go with tonyyeb. You have to use exec() to execute programs.

tonyyeb
01-04-2008, 03:01 PM
I did take a look at this but didn't find it very helpful unfortunately

Check my edit above ^^^^^^^

Also here are the Daemon tool command line switches. Should be a doddle now!

http://www.daemon-help.com/index.php?id=cmd_line_switches

blackfish
01-04-2008, 04:09 PM
Excellent guys, thanks very much for your help, I shall update you on the results :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum