Solved

2-way communication

Posted on 1997-05-03
4
220 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now