Hello everyone,
first this is a fanastic website. I really like it.
Now to my problem.
I have a linux terminal program which waits for user input a.k.a. a user to press the return key to get back to the terminal prompt again.
So basically I want to parse the stdout off that program ( i need information about the parameters).
So I made the following:
my $parameter_output = `echo "\n" |programname -help`;
and this works perfectally well for me, the program terminates, the complete stdout is stored in that variable and my perl script moves on...
But I thought to me..."hey all this commandline statement above is doing is forking a process and putting that newline character from the stdout from process 1 (parent) to stdin from the second process(child)".
So I tried to reproduce this with fork but I cannot find the reason why this does not work.
small snippet....
pipe (IN,OUT);
my $pid = fork ();
die("fork failed") if (!defined($pid));
if ($pid == 0 ) {
#the child
exec ('programname -help');
}
else {
#parent
sleep (2);
#printing the newline character in the child process
print OUT "\n";
waitpid ($pid,0);
}
I also tried this with signals....
snippet:
sub print_it {print "\n"};
my $SIG{INT}=\&print_it;
....
else {
#parent
sleep (2);
kill INT=>$pid;
waitpid ($pid,0);
}
neither this works....
I think somewhere I have a big error in reasoning I think.
So it would be very kind if someone could help me.
Thanks in advance
joshi
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.