Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Speaking Of Pipes 1

Status
Not open for further replies.

sleuth

Programmer
Jan 12, 2001
134
0
0
US

If I open a pipe to a program, an incomming pipe,

How do I capture the information it outputs?

Tony "Java?? Umm, I think that's the stuff I drink while I'm coding perl."
 
you treat it like a filehandle (a filehandle is just a specific case of a general IO), and say something like &quot;while (<PIPE>) {}&quot; to get the output a line at a time.
that is in the case of a unidirectional pipe, opened for reading. if you need a pipe you can write to and read to, you'll need to use 'IPC::Open2', which you can learn more about with 'perldoc IPC::Open2' (POSIX only). &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 

Ok, I had a feeling it would be like that,

I'll let you know if the experiment works,

Tony &quot;Java?? Umm, I think that's the stuff I drink while I'm coding perl.&quot;
 
yep, like this:

open(LS,&quot;ls -la|&quot;) || die;
while(<LS>){
print if /^d/;
}

this fragment of code will print the ls -la lines for all directories in the current directory. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Darn, didn't work, I tried opening a pipe like this,

open(PERL, &quot;/usr/bin/perl /home/bin/test.cgi|&quot;);
while(<PERL>){
push(@compiled,$_);
}
close(perl);
open(data, &quot;>test.exe&quot;);
binmode data;
print data @compiled;
close(data);

Of course it only gave me the out put, darn, I thought i might just have worked.

I was really just looking for a way to do it on windows.

Tony &quot;Java?? Umm, I think that's the stuff I drink while I'm coding perl.&quot;
 
Ahhh -- *now* I see what you're after. You want a compiled version of your perl script.

Well -- it's possible.

PerlApp -- from ActiveState for NT is reputed to be quite good, but you have to buy it.

Perlcc -- comes with standard perl and is documented with the rest of perl. It's a translator rather than a compiler, it turns your perl code into C code, which you can then compile using the gnu compiler. You can also get it to produce bytecode that can be executed using perl, but can't be read by a person.

Is that what you meant? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
your close statement should be:[tt]
close PERL;
[/tt]
(filehandles are case sensitive)
and you can also simplify your loop into this:[tt]
@compiled = <PERL>;
[/tt]

but as for your intentions, did you want to make an executable out of the perl script? there are ways to do this (perl2exe, undump, that one thing from activestate), discussed recently on this forum... &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 

Whatever, I just wrote that out real quick, hehe, I actually had other code I was using, Thanks though,

I don't have an NT server, and perlcc works fine, but of course only for linux, I'm more worried about NT.

So about perl2exe, it's a piece of crap. If you've gotten a script to run outside of dos without any Tk then I'd love you for it though. I'd buy it then.

Tony &quot;Java?? Umm, I think that's the stuff I drink while I'm coding perl.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top