Solved

2-way communication

Posted on 1997-05-03
4
226 Views
Last Modified: 2006-11-17
I need to do the following because I am using mod_perl and I do not want to write then read from a temp file:

1. My script pipes info to gnuplot beta 3.6.
2. Gnuplot reads config info from standard in, creates plot in GIF format and outputs it on standard out.
3. My script captures gnuplot output to a varaible.
4. My script outputs varaible to web page.

I tried IPC::Open2 but could not capture all the output.
0
Comment
Question by:hartlieb
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
n3mtr earned 75 total points
ID: 1203909
You need to use a child process for this one.
Try this:
pipe(PARENT,CHILD);
if(! fork()){
   #this is executed by the child
   close(PARENT);
   open(STDOUT,">&CHILD"); #redirect stdout to child pipe
   open(PLOT,"|gnuplot");
   #print your output to gnuplot here
   close(PLOT);
   close(CHILD);
   close(STDOUT);
   exit; #end child process
} else {
   #this is executed by the parent
   close(CHILD);
   #gnuplot output is available with the PARENT filehandle
   close(PARENT);
}
If you have any questions about how it works, just ask.
0
 

Author Comment

by:hartlieb
ID: 1203910
This works but I need to clarify how to get all the output
from gnuplot.

I tried the following and It seems to work.

while (<PARENT>) {
   $Gif .= $_;
}

Is there a better way as the output from gnuplot is binary?

Thanks for the quick response,


0
 
LVL 2

Expert Comment

by:n3mtr
ID: 1203911
do this:
undef($/); #make sure this is a forward slash
$Gif = <PARENT>;

undefining the $/ makes it read the whole file(pipe) at once.
You may want to change it back to $/="\n"; if you read any files after this one.

0
 

Author Comment

by:hartlieb
ID: 1203912
Thanks for the quick response. It was a nagging problem.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question