did you try reading the docs? You didn't even try to use my example. perldoc IPC::Open2
> -----Original Message----- > From: Tirthankar C. Patnaik [mailto:[EMAIL PROTECTED]] > Sent: Friday, April 12, 2002 1:52 PM > To: Nikola Janceski > Cc: [EMAIL PROTECTED] > Subject: RE: Input | Program | Output : help > > > > I'm afraid I couldn't succeed in using the IPC::Open2 module. > Where am I > going wrong? > > # } > my($IN,$OUT); > open(OUT,"| discretise ${delta} ${BOD} ${EOD}") || die > "Sorry out: $!"; > > if($suffix eq ".par"){ > open(IN,"<$ParseFile") || die "Sorry: $!"; > open2('IN','OUT'); > } > > Could you please explain the code, in more detail? > > TIA, > -tir > > > } > > > On Fri, 12 Apr 2002, Nikola Janceski wrote: > > > You might want to look at IPC::Open2 > > > > You can open a system command with an INPUT pipe and OUTPUT pipe. > > > > Here is how I used it. > > > > open2(*READ, *ZIPIT, "/apps/bin/zip $FORM{'zipfile'} -@ 2>&1"); > > READ is the input pipe > > ZIPIT is the output pipe > > > > Perl Gurus, Yeah I should have used the ZIP module.. I am > too lazy to change > > it now. > > > > > > > -----Original Message----- > > > From: Tirthankar C. Patnaik [mailto:[EMAIL PROTECTED]] > > > Sent: Friday, April 12, 2002 1:04 PM > > > To: [EMAIL PROTECTED] > > > Subject: Input | Program | Output : help > > > > > > > > > > > > > > > Folks, > > > Consider this code snippet: > > > > > > Here $ParseFile is a plain-text file, which could be gzipped, > > > bzipped, or > > > not compressed at all. I'd like my program to determine > this, open the > > > file, and cat it to another program called discretise. > > > > > > In the code below, > > > > > > my(@PARSELIST) = @ARGV; # This would be the .par files. > > > my($ParseFile); > > > for $ParseFile (@PARSELIST){ > > > chomp $ParseFile; > > > my($date,$name,$suffix) = &FileTest($ParseFile); # uses > > > File::Basename > > > if($suffix eq ".bz2"){ > > > system("bunzip2 -c $ParseFile | discretise $delta > > > $BOD $EOD > ${OUTFILE}"); > > > }elsif($suffix eq ".gz"){ > > > system("gunzip -c $ParseFile | discretise $delta $BOD > > > $EOD > ${OUTFILE}"); > > > }elsif($suffix eq ".par"){ > > > system("cat $ParseFile | discretise $delta $BOD $EOD > > > > ${OUTFILE}"); > > > } > > > > > > > > > As you can see, I've got three system commands to run on > $ParseFile, > > > depending on it's extn (.par/.gz/.bz2). > > > > > > I don't know how I should ask this, but can I > > > > > > 1. open $ParseFile and assign a filehandle to it (IN), say. > > > 2. open $Outfile and assign a filehandle to it (OUT), > > > 3. determine the extension of the input file, > > > > > > And this is the important part: > > > 4. Depending on the extension, cat, gunzip -c, or bunzip > > > -c the input > > > file to the output file, using the _filehandle_, > > > without a system > > > command. > > > > > > Is this possible in Perl, if so how to do it? And is it > > > necessary? > > > > > > For instance, I could have, > > > > > > if($suffix eq ".bz2"){ > > > open(IN, "bunzip2 -c $ParseFile|") > > > ||die "Could not open $ParseFile: $!"; > > > }elsif($suffix eq ".gz"){ > > > open(IN, "gunzip -c $ParseFile|") > > > ||die "Could not open $ParseFile: $!"; > > > }elsif($suffix eq ".par"){ > > > open(IN, "<$ParseFile") > > > || die "Could not open $ParseFile: $!"; > > > } > > > > > > And then I open an output file: > > > > > > > > > open(OUT, "| discretise delta BOD EOD > $OutFile") || die > > > "Sorry :$!"; > > > > > > Problem: How do I channel the input from $ParseFile to the > > > OUT filehandle? > > > > > > Please explain in --verbose mode! I do not know these things. :) > > > > > > -tir > > > > > > > > > TIA, > > > > > > > > > > > > > > > > > > > > > -- > > > Tirthankar, IGIDR. > > > +91-22-8400919 x275 (r), x593(o), x542(CFL). > > > http://www.igidr.ac.in/~tir > > > > > > ACKNOWLEDGE, v.t. To confess. Acknowledgement of one another's > > > faults is the highest duty imposed by our love of truth. > > > > > > > > > -- > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > -------------------------------------------------------------- > -------------- > > -------------------- > > The views and opinions expressed in this email message are > the sender's > > own, and do not necessarily represent the views and > opinions of Summit > > Systems Inc. > > > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > -- > Tirthankar, IGIDR. > +91-22-8400919 x275 (r), x593(o), x542(CFL). > http://www.igidr.ac.in/~tir > > SUCCESS, n. The one unpardonable sin against one's fellows. In > literature, and particularly in poetry, the elements of success are > exceedingly simple, and are admirably set forth in the > following lines > by the reverend Father Gassalasca Jape, entitled, for some > mysterious > reason, "John A. Joyce." > > The bard who would prosper must carry a book, > Do his thinking in prose and wear > A crimson cravat, a far-away look > And a head of hexameter hair. > Be thin in your thought and your body'll be fat; > If you wear your hair long you needn't your hat. > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > ---------------------------------------------------------------------------- -------------------- The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]