Solved

2-way communication

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add a syntax to a csv file 8 98
Regular Expression for URL 10 91
Matching a random pattern with one common character 2 45
Perl Untar File 1 27
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

896 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

13 Experts available now in Live!

Get 1:1 Help Now