J
Jerry Krinock
Markdown.pl is a Perl text-processing filter which takes input from
stdin and outputs to stdout. I'd like to call it as a child process
from within my script -- pass it a string and get a string back. I've
come to believe that this requires something like IPC::Open2
pen2()
and have written the following code. However, the child process never
exits, as though maybe it's waiting for the stdin pipe to close.
What's wrong with this code?...
#!/usr/bin/perl
require IPC::Open2 ;
use strict ;
my $markdownIn = "*Hello* **World**\n" ;
print ("markdownIn = $markdownIn") ;
my $cmd = '/Users/jk/Downloads/Markdown_1.0.1/Markdown.pl';
my $markdownOut ;
my $childpid = IPC::Open2:
pen2($markdownOut, $markdownIn, $cmd)
or die "can't open pipe to $cmd: $!";
waitpid( $childpid, 0 );
my $cmdExitStatus = $? >> 8;
print ("cmdExitStatus = $cmdExitStatus\n") ;
print ("markdownOut = $markdownOut\n") ;
If I comment out the waitpid(), then it runs but does not give the
desired result:
markdownIn = *Hello* **World**
cmdExitStatus = 0
markdownOut = GLOB(0x816b3c)
Markdown.pl definitely works fine if I give it that string from stdin
in a bash shell:
Jerrys-Mac-Mini:~ jk$ echo "*Hello* **World**\n" | /Users/jk/Downloads/
Markdown_1.0.1/Markdown.pl
<p><em>Hello</em> <strong>World</strong>\n</p>
Thank you!
Jerry Krinock
stdin and outputs to stdout. I'd like to call it as a child process
from within my script -- pass it a string and get a string back. I've
come to believe that this requires something like IPC::Open2
and have written the following code. However, the child process never
exits, as though maybe it's waiting for the stdin pipe to close.
What's wrong with this code?...
#!/usr/bin/perl
require IPC::Open2 ;
use strict ;
my $markdownIn = "*Hello* **World**\n" ;
print ("markdownIn = $markdownIn") ;
my $cmd = '/Users/jk/Downloads/Markdown_1.0.1/Markdown.pl';
my $markdownOut ;
my $childpid = IPC::Open2:
or die "can't open pipe to $cmd: $!";
waitpid( $childpid, 0 );
my $cmdExitStatus = $? >> 8;
print ("cmdExitStatus = $cmdExitStatus\n") ;
print ("markdownOut = $markdownOut\n") ;
If I comment out the waitpid(), then it runs but does not give the
desired result:
markdownIn = *Hello* **World**
cmdExitStatus = 0
markdownOut = GLOB(0x816b3c)
Markdown.pl definitely works fine if I give it that string from stdin
in a bash shell:
Jerrys-Mac-Mini:~ jk$ echo "*Hello* **World**\n" | /Users/jk/Downloads/
Markdown_1.0.1/Markdown.pl
<p><em>Hello</em> <strong>World</strong>\n</p>
Thank you!
Jerry Krinock