Jump to content

write standard error into file


yunfong

Recommended Posts

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

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');
?>

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!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.