Solved

2-way communication

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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Remove Malware code from PHP file 6 85
grep that displays 4 lines above & 1 line below of what's found 10 82
Extract data from span tag 1 93
Perl modules on linux ec2 3 107
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

831 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