FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Pipe the content of a variable to a process
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Pipe the content of a variable to a process [message #173024 is a reply to message #173021] Fri, 18 March 2011 02:30 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 3/17/2011 5:35 PM, Marco wrote:
> On 2011-03-17 Marco<netuse(at)lavabit(dot)com> wrote:
>
>> Hi,
>>
>> how can I pipe the content of a variable into a process' standard input and
>> save its output into another variable?
>> [...]
>
> I made some progress. But I still have problems. In the following example I
> can use »cat« as process without problems. But gnuplot produces no output, but
> a return value of zero, that means it's successfull. But where's the output?
>
> When I call gnuplot with the »passthru« command it works as expected that
> means that it is in the PATH and produces output on stdout with the given
> input. What's the problem here?
>
> <?php
> $stdin_data = 'set terminal svg;plot sin(x)';
>
> $descriptorspec = array(
> 0 => array( 'pipe', 'r' ), // stdin to read from
> 1 => array( 'pipe', 'w' ), // stdout to write to
> 2 => array( 'pipe', 'a' ), // stderr
> );
>
> // This works
> // $process = proc_open( 'cat', $descriptorspec, $pipes );
>
> // This doesn't produce output
> $process = proc_open( 'gnuplot', $descriptorspec, $pipes );
>
> if ( is_resource( $process ) ) {
> fwrite( $pipes[0], $stdin_data );
> fclose( $pipes[0] );
> $content = stream_get_contents( $pipes[1] );
> fclose( $pipes[1] );
> fclose( $pipes[2] );
>
> $return_value = proc_close( $process );
>
> // cat and gnuplot return 0
> echo $return_value . "\n";
> echo $content;
>
> // This works
> // passthru( "gnuplot -e '$stdin_data'" );
> }
> ?>
>
>
> Marco
>

What's in stderr? What happens if you write stdout and stderr to a file
(for testing)?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: use of array_key_exists() to prevent duplicates?
Next Topic: $_POST not set on 404
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 11:58:24 GMT 2024

Total time taken to generate the page: 0.03895 seconds