note 57538 added to function.exec
| From: | rivera at spamjoy dot unr dot edu | Date: | Thu, 06 Oct 2005 20:17:00 +0000 |
| Subject: | note 57538 added to function.exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96526@lists.php.net to get a copy of this message | ||
windExec() reloaded:
* unique timestamp name was probably a good idea for multiple instances of function running @ same
time
* includes handy FG/BG parameter
<?php
define ('EXEC_TMP_DIR', 'C:\tmp');
function windExec($cmd,$mode=''){
// runs a command line and returns
// the output even for Wind XP SP2
// example: $cmd = "fullpath.exe -arg1 -arg2"
// $outputString = windExec($cmd, "FG");
// OR windExec($cmd);
// (no output since it runs in BG by default)
// for output requires that EXEC_TMP_DIR be defined
// Setup the command to run from "run"
$cmdline = "cmd /C $cmd";
// set-up the output and mode
if ($mode=='FG'){
$outputfile = EXEC_TMP_DIR . "\\" . time() . ".txt";
$cmdline .= " > $outputfile";
$m = true;
}
else $m = false;
// 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, $m);
if ($outputfile){
// Read the tmp file.
$retStr = file_get_contents($outputfile);
// Delete the temp_file.
unlink($outputfile);
}
else $retStr = "";
return $retStr;
}
----
Manual Page -- http://www.php.net/manual/en/function.exec.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57538
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57538&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57538&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57538&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57538&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57538&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57538&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57538&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57538&report=yes
Search -- http://master.php.net/manage/user-notes.php