note 57505 deleted from function.exec by cece
| From: | cece@php.net | Date: | Tue, 17 Jan 2006 15:01:07 +0000 |
| Subject: | note 57505 deleted from function.exec by cece | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-101970@lists.php.net to get a copy of this message | ||
Note Submitter: rivera at FOO dot cse dot unr dot edu
----
in response to chads2k2.yahoo.com
nice one!
only way I got
WindXP SP2
Apache 2.0.54
PHP 5.0.4
to exec anything.
your code encapsulated:
<?php
function windExec($cmd,$outputfile = "C:\\tmp\\tmp.txt"){
// runs a command line and returns
// the output even for Wind XP SP2
// example: $cmd = "fullpath.exe -arg1 -arg2"
// $outputString = windExec($cmd,"C:\\my_alternate\\path_to\\a_tmp_file.txt");
// Setup the command to run from "run"
$cmdline = "cmd /C $cmd > $outputfile";
// Make a new instance of the COM object
$WshShell = new COM("WScript.Shell");
// Make the command window but dont show it.
$oExec = $WshShell->Run($cmdline, 0, true);
// Read the file file.
$retArr = file($outputfile);
// Delete the temp_file.
unlink($outputfile);
// convert array to string
$retStr = implode(' ', $retArr);
return $retStr;
}
?>
Piece.