note 57538 deleted from function.exec by cmb

From: Date: Sun, 24 Nov 2019 08:43:46 +0000
Subject: note 57538 deleted from function.exec by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213203@lists.php.net to get a copy of this message
Note Submitter: rivera at spamjoy dot unr dot edu ---- 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; }

« previous php.notes (#213203) next »