"Compiling c prog using gcc in PHP"
Hi all,
I know that we can use UNIX commands in PHP by the 'system' or 'exec' functions in PHP .... Main Problem is this::: When I do like this.. $ls=system("ls"); echo $ls; /* It is printing all the files in the directory */ But when I do this :::: $filename="somefile.txt" /* Remember it is a text file */ $output=system("gcc $filename"); /* This is certainly an error And I want the error to be printed on to the page */ print $output; /* Is not giving me what I want */ Can neone tell me how to get the error messages like which we usually get when we compile a text file in LInux with gcc compiler or any other compiler ThanX in Anticipation. |
go to read function popen
http://sg2.php.net/manual/en/function.popen.php |
or alternatively sh_exec()
http://sg2.php.net/manual/en/function.shell-exec.php |
I take it that somefile.txt is not a C source file (which is a special case of text file). In this case, do you want to capture the errors produced by gcc?
Error messages are usually sent to the standard error output stream, rather than the standard output that you are collecting with the system() command. You can use the shell to redirect standard error to standard output, so it can be captured, using 2>&1 like this: Code:
gcc somefile.txt 2>&1 Code:
$output=system("sh -c 'gcc $filename 2>&1'"); Hope that helps, — Robert J. Lee |
ThanQ U For U help..... It's working fine
|
All times are GMT -5. The time now is 11:54 AM. |