[SOLVED] running commandline exe in windows
Posted: Wed Jun 08, 2005 5:39 pm
I've searched and gone through loads of information on the subject of using exec() on windows but I still can't seem to get this working.
PHP 4.3.11, Apache 1.3.33, Windows XP SP1
I have a command-line exe file located in c:\scripts
My PHP scripts are located in c:\htdocs
The command-line exe is called CLamp.exe and is a WinAmp plugin to check/control the status of winamp 5 on that machine.
When you call CLamp.exe with various switches you can do various things.
I'm trying to do this through a web interface.
I just need to get the result of the command
In the PHP manual there's lots going on about hiding the window, minimising the window, and frankly I don't really care.
It would be nice if it was completely hidden, but just so long as it works.
On the user notes of the exec() function in the php manual, I've tried using the example from chads2k2.yahoo.com and modifying it slightly.
All I get however is "Didn't go smoothly"
When the output I should get (hopefully) is "No option" (because I didn't specify any switches in $cmd
Any ideas on where I'm going wrong with this?
I've tried all the different methods mentioned on the manual page, but this method seems to be the one best suited to what I'm looking for here.
Thanks
Ben
PHP 4.3.11, Apache 1.3.33, Windows XP SP1
I have a command-line exe file located in c:\scripts
My PHP scripts are located in c:\htdocs
The command-line exe is called CLamp.exe and is a WinAmp plugin to check/control the status of winamp 5 on that machine.
When you call CLamp.exe with various switches you can do various things.
I'm trying to do this through a web interface.
I just need to get the result of the command
In the PHP manual there's lots going on about hiding the window, minimising the window, and frankly I don't really care.
It would be nice if it was completely hidden, but just so long as it works.
On the user notes of the exec() function in the php manual, I've tried using the example from chads2k2.yahoo.com and modifying it slightly.
Code: Select all
<?php
// Get a good ol' timestamp. Unique and it works.
$unixtime = time();
// Sets up your exe or other path.
$cmd = 'c:\\scripts\\clamp.exe';
// Setup an array of arguments to be sent.
$arg[] = '1';
$arg[] = '2';
$arg[] = '3';
$arg[] = '4';
$arg[] = '5';
// Pick a place for the temp_file to be placed.
$outputfile = 'c:\\scripts\\unixtime.txt';
// Setup the command to run from "run"
$cmdline = "cmd /C $cmd " . implode(' ', $arg) . " > $outputfile";
// Make a new instance of the COM object
$WshShell = new COM("WScript.Shell");
// Make the command window but don't show it.
$oExec = $WshShell->Run($cmdline, 0, true);
// Read the file file.
$output = file($outputfile);
// Delete the temp_file.
unlink($outputfile);
// Take the output and break the array apart.
// If you don't know what is coming out do:
// print_r("$output");
foreach($output as $temp_output)
{
// Check the output's return code.
if($temp_output == 1)
{
// Tell the user it was correct.
echo "All is good";
}else{
// Tell the user something goofed.
echo "Didn't go smoothly.";
}
}
?>When the output I should get (hopefully) is "No option" (because I didn't specify any switches in $cmd
Any ideas on where I'm going wrong with this?
I've tried all the different methods mentioned on the manual page, but this method seems to be the one best suited to what I'm looking for here.
Thanks
Ben