note 57505 added to function.exec
| From: | rivera at FOO dot cse dot unr dot edu | Date: | Thu, 06 Oct 2005 05:17:34 +0000 |
| Subject: | note 57505 added to function.exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96469@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.exec.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57505
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57505&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57505&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57505&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57505&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57505&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57505&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57505&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57505&report=yes
Search -- http://master.php.net/manage/user-notes.php