Execute appliction and pass parameters to it!
| From: | Dipesh Khakhkhar | Date: | Tue, 29 Mar 2005 18:38:50 +0000 |
| Subject: | Execute appliction and pass parameters to it! | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-211805@lists.php.net to get a copy of this message | ||
Hi,
I am trying to execute one application (bat file) and need to pass parameter to it. I want to put
this into wrapper file which i can call over http. Can i do this?
I tried the following:
------------------------------------------------------------------
1) $output = shell_exec('..\phpunit.bat C:\Run.php');
echo $output;
Result: No output. Nothing happened.
2) $cmd = '..\..\phpunit.bat';
// Setup an array of arguments to be sent.
$arg[] = "..\..\Run.php";
// Pick a place for the temp_file to be placed.
$outputfile = '..\..\CMDOUT.txt';
// Setup the command to run from "run"
$cmdline = "cmd /C $cmd " . implode(' ', $arg) ;
try
{
echo "Came in try";
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run($cmdline, 3, true);
echo $oExec; // This is not getting printed.
echo "Coming out of try";
}
catch(Exception $e)
{
echo "came in catch";
print("Caught Exception in " .
$e->file() . " on line " .
$e->line() . "<br>\n");
}
Result: Nothing is happening. It is printing both the statements in the try block.
3) $firstArg = "C:\\..\\..\\Run.php";
$output = exec("C:\\..\\..\\phpunit.bat $firstArg");
Result: Still nothing is happening.
4)$output = exec("C:\\..\\..\\phpunit.bat $firstArg 2>&1", $myOut);
echo "<br/>My out value is ".$myOut;
Result: My out value is Array operable program or batch file.
--------------------------------------------------------------
All the above approaches not working for me.
Can somebody inform me where i need to make changes.
Thanks in advance.
Regards,
Dipesh