Re: Input from subprocess called using open() buffered?
From: g r a e m e b [at] c a d e n c e [dot] c o m ("g)
Date: 08/09/04
- Next message: Daniel Miller: "Re: Program slows as I run it"
- Previous message: Tim Hammerquist: "Re: chmod for directories"
- In reply to: 510046470588-0001_at_t-online.de: "Re: Input from subprocess called using open() buffered?"
- Next in thread: g r a e m e b [at] c a d e n c e [dot] c o m: "Re: Input from subprocess called using open() buffered?"
- Reply: g r a e m e b [at] c a d e n c e [dot] c o m: "Re: Input from subprocess called using open() buffered?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 09 Aug 2004 18:51:43 +0100
Success! :)
Thanks for all the replies, I managed to get two solutions which do what I
want, neither of which are probably correct! ;D
The first one, using raw IO::Pty, looks a little like this:
my $pty = new IO::Pty;
my $ttyname = $pty->ttyname();
print "Spawned tty $ttyname\n";
open(COMMAND, "$cmd > $ttyname 2>&1|") || die "Couldn't run command";
while(<$pty>) {
print ":: $_";
}
close($pty);
I take it that I'm supposed to run the command and direct the IO manually to
the pty I've opened (eg. "cvs update > /dev/pty56 2>&1")? This seems to work
fine, I just want to check I'm using it correctly.
I am a bit baffled as to why I need to have COMMAND as a filehandle - is there
a better way of doing this? And do I need to close both $pty and COMMAND?
Presumably all the output is going to $pty, so I don't even need COMMAND, or do I?
The other method, using Expect, looked a little like this (note that I hacked
this up BEFORE looking at the Expect docs!):
my $process = Expect->spawn("$cmd 2>&1");
while (<$process>) {
print "|| $_";
}
close($process);
It's more succinct than the one above, but when I looked at the docs, it didn't
seem to even mention being able to loop over the filehandle returned (in the
question about "what if I only want to get output without 'expecting'
anything?". Not sure if this works by accident or design!
Any code criticism welcome...
Thanks,
Graeme.
PS. I was running 'cvs update' (and checkout) - it does indeed have the same
effect if I do 'cvs update 2>&1 | cat'. Thanks, I thought this was an obscure
perl thing, didn't realise other programs actually did different things
depending upon the output file...
510046470588-0001@t-online.de wrote:
> Brian McCauley <nobull@mail.com> writes:
>
>>Failing that, I Expect (hint, hint) there's something on CPAN you
>>could use to allow Perl to fool the other process into thinking its
>>output was going to a terminal.
>
>
>
> IO::Pty, which comes with IO::Tty
>
> Klaus Schilling
- Next message: Daniel Miller: "Re: Program slows as I run it"
- Previous message: Tim Hammerquist: "Re: chmod for directories"
- In reply to: 510046470588-0001_at_t-online.de: "Re: Input from subprocess called using open() buffered?"
- Next in thread: g r a e m e b [at] c a d e n c e [dot] c o m: "Re: Input from subprocess called using open() buffered?"
- Reply: g r a e m e b [at] c a d e n c e [dot] c o m: "Re: Input from subprocess called using open() buffered?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|