I am writing a shell to process the web log. One operation is written in php and called in the bash shell, it accept a stdin from the previous pipe and produce the output to the next pipe. I am wondering how to produce the output for the next pipe. I have already tested $stdin = fwrite(STDOUT, $data);
it seems that it is not OK that way. Any solutions for me? Thank you so much!
I usually just use echo
, or if I need a file I open "php://stdout"
for writing.
If you have a PHP that is accepting bash command arguments (and this can be via stdin from a pipe), you can access the arguments using the variable $argv inside the script, which houses the arguments as an array delimited by whitespaces (http://php.net/manual/en/reserved.variables.argv.php).
If you want the PHP to be able to stdout and pipe its output to another script, you can simply print or echo the statement and it should be implicitly in the stdout stream, if I'm not mistaken.
You can use echo or print to write to stdout. In any case STDOUT isn't a constant I'm familiar with. PHP has some special wrappers you can use with fopen to do what you need.