yunfong Posted March 28, 2009 Share Posted March 28, 2009 hi, Please help me! i got a problem which i need to run a command and write the standard error output into a file.. $cmd = "cmd /c siftWin32 <".$fileN.".pgm >".$fileN.".key"; the above is my command which i try to use proc_open() to read the standard error which dsnt help. $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("file","error.txt", "w") // stderr is a file to write to ); $process = proc_open($cmd, $descriptorspec, $pipes); stream_set_blocking($pipes[2], 0); if(is_resource($process)) { $StdErr = ''; $StdErr = stream_get_contents($pipes[2]); fclose($pipes[2]); } proc_close($process); error.txt shows "The system cannot find the file specified." .key files are generated by that command.. my .pgm file was created earlier.. wat should i do? Please help!! Link to comment https://forums.phpfreaks.com/topic/151519-write-standard-error-into-file/ Share on other sites More sharing options...
yunfong Posted March 28, 2009 Author Share Posted March 28, 2009 the standard output is my .key file which proc_open dsnt execute at all.. the standard error is the no of keypoints which the image file has.. if i use exec($cmd) it will generate .key file but not for proc_open. Link to comment https://forums.phpfreaks.com/topic/151519-write-standard-error-into-file/#findComment-795831 Share on other sites More sharing options...
chmpdog Posted March 28, 2009 Share Posted March 28, 2009 Do you have to use this code? Because I have a nifty error log that works. Link to comment https://forums.phpfreaks.com/topic/151519-write-standard-error-into-file/#findComment-795844 Share on other sites More sharing options...
yunfong Posted March 28, 2009 Author Share Posted March 28, 2009 hi, wat error log do u haf? i only wan to execute the "cmd /c siftWin32 etc" and print the output code.. i dun reali need proc_open.. as long as it runs can alr.. i used exec($cmd) for other applications and it works! Thanks!! Link to comment https://forums.phpfreaks.com/topic/151519-write-standard-error-into-file/#findComment-795850 Share on other sites More sharing options...
chmpdog Posted March 29, 2009 Share Posted March 29, 2009 I use the following code. It will show all errors in error_log.txt. Hope it helps: <?php /* we will do our own error handling. */ error_reporting(0); // Turns off all error reporting. /* user defined error handling function. */ function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars) { // timestamp for the error entry. $dt = date('Y-m-d H:i:s (T)'); // define an assoc array of error string // in reality the only entries we should // consider are E_WARNING, E_NOTICE, E_USER_ERROR, // E_USER_WARNING and E_USER_NOTICE. $errortype = array ( E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parsing Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_STRICT => 'Runtime Notice' ); // set of errors for which a var trace will be saved. $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE); $err = "\n-----------------------\n"; $err .= "\t" .$dt. "\n"; $err .= "\t" .$errno. "\n"; $err .= "\t" .$errortype[$errno]. "\n"; $err .= "\t" .$errmsg. "\n"; $err .= "\t" .$filename. "\n"; $err .= "\t" .$linenum. "\n"; if (in_array($errno, $user_errors)) { $err .= "\tvartrace\t" .wddx_serialize_value($vars, 'Variables'). "\n"; } $err .= "\n"; // save to the error log file, and e-mail me if there is a critical user error. error_log($err, 3, 'error_log.txt'); if ($errno == E_USER_ERROR) { mail('[email protected]', 'Critical User Error', $err); } } $old_error_handler = set_error_handler('userErrorHandler'); ?> Link to comment https://forums.phpfreaks.com/topic/151519-write-standard-error-into-file/#findComment-796092 Share on other sites More sharing options...
redarrow Posted March 29, 2009 Share Posted March 29, 2009 Nice code simple but works, i guess it used when distributing scripts, to tell what gong on in support off the script distributed. Link to comment https://forums.phpfreaks.com/topic/151519-write-standard-error-into-file/#findComment-796143 Share on other sites More sharing options...
yunfong Posted April 1, 2009 Author Share Posted April 1, 2009 hi chmpdog, i read your code but what parameters should i give as input? Thanks!! sorry for e late reply as i was busy wif other projs.. Link to comment https://forums.phpfreaks.com/topic/151519-write-standard-error-into-file/#findComment-798411 Share on other sites More sharing options...
yunfong Posted April 1, 2009 Author Share Posted April 1, 2009 hi, how to write the standard eror into file after i run an external program? the output of the file is a floating point number in .key file and i want both the standard output .key file and standard error is the result obtained after running the program. How to do it? does anybody know?? Thanks!! i am very eager to do tis as my prof rushing for it now.. Please help!! Link to comment https://forums.phpfreaks.com/topic/151519-write-standard-error-into-file/#findComment-798709 Share on other sites More sharing options...
chmpdog Posted April 1, 2009 Share Posted April 1, 2009 hi chmpdog, i read your code but what parameters should i give as input? Thanks!! sorry for e late reply as i was busy wif other projs.. Just include it on the page, it will do the rest. As for your other question im not sure.. Link to comment https://forums.phpfreaks.com/topic/151519-write-standard-error-into-file/#findComment-799064 Share on other sites More sharing options...
yunfong Posted April 2, 2009 Author Share Posted April 2, 2009 alright, thanks!! i wil go n try now.. Link to comment https://forums.phpfreaks.com/topic/151519-write-standard-error-into-file/#findComment-799173 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.