|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
i am using cpan2rpm to generate RPMS from CPAN perl modules. The script (cpan2rpm is a perl script) uses several non standard file descriptors for output (i.e., saves the descriptors, redirects some output to /dev/null, and restores them). Now I would like to parse the output of cpan2rpm but it seems that is neither on stdout nor in stderr: cpan2rpm Class::Accessor > /dev/null 1> /dev/null 2> /dev/null produces Generating spec file SPEC: /usr/src/redhat/SPECS/Class-Accessor.spec RPM: /usr/src/redhat/RPMS/noarch/perl-Class- Accessor-0.31-1.noarch.rpm SRPM: /usr/src/redhat/SRPMS/perl-Class-Accessor-0.31-1.src.rpm How can I store this output to a variable (or file)? This is what cpan2rpm does: open(OLDOUT, ">&STDOUT") || die "std_save(): $!"; open(OLDERR, ">&STDERR") || die "std_save(): $!"; open(OLDIN, "<&STDIN") || die "std_save(): $!"; open(STDOUT, ">/dev/null") || die "std_close(): $!"; open(STDERR, ">/dev/null") || die "std_close(): $!"; open(STDIN, "</dev/null") || die "std_close(): $!"; [...] open(STDOUT, ">&OLDOUT") || die "std_restore(): $!"; open(STDERR, ">&OLDERR") || die "std_restore(): $!"; open(STDIN, "<&OLDIN") || die "std_restore(): $!"; Many thanks, Matteo |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Hi again,
On Mar 14, 4:29 pm, Teo <matteo.co...@gmail.com> wrote: > i am using cpan2rpm to generate RPMS from CPAN perl modules. The > script (cpan2rpm is a perl script) uses several non standard file > descriptors for output (i.e., saves the descriptors, redirects some > output to /dev/null, and restores them). > > Now I would like to parse the output of cpan2rpm but it seems that is > neither on stdout nor in stderr: > > cpan2rpm Class::Accessor > /dev/null 1> /dev/null 2> /dev/null > > produces > > Generating spec file > SPEC: /usr/src/redhat/SPECS/Class-Accessor.spec > RPM: /usr/src/redhat/RPMS/noarch/perl-Class- > Accessor-0.31-1.noarch.rpm > SRPM: /usr/src/redhat/SRPMS/perl-Class-Accessor-0.31-1.src.rpm > > How can I store this output to a variable (or file)? [...] Nevemind looking at the sources I found out an option --keep-pipes :-) But I would be glad to know how to handle similar cases. Thanks anyway Matteo |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
In article
<6d71ad7a-e06b-48fc-8804-7ffbff43f58d@h11g2000prf.googlegroups.com>, Teo <matteo.corti@gmail.com> wrote: > Hi again, > > On Mar 14, 4:29 pm, Teo <matteo.co...@gmail.com> wrote: > > i am using cpan2rpm to generate RPMS from CPAN perl modules. The > > script (cpan2rpm is a perl script) uses several non standard file > > descriptors for output (i.e., saves the descriptors, redirects some > > output to /dev/null, and restores them). > > > > Now I would like to parse the output of cpan2rpm but it seems that is > > neither on stdout nor in stderr: > > > > cpan2rpm Class::Accessor > /dev/null 1> /dev/null 2> /dev/null > > > > produces > > > > Generating spec file > > SPEC: /usr/src/redhat/SPECS/Class-Accessor.spec > > RPM: /usr/src/redhat/RPMS/noarch/perl-Class- > > Accessor-0.31-1.noarch.rpm > > SRPM: /usr/src/redhat/SRPMS/perl-Class-Accessor-0.31-1.src.rpm > > > > How can I store this output to a variable (or file)? > [...] > > Nevemind looking at the sources I found out an option --keep-pipes :-) > But I would be glad to know how to handle similar cases. Since this isn't a common behavior, there aren't really any "similar cases". Any program that does this is ideosyncratic, and the solution depends on how that program is designed. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE don't copy me on replies, I'll read them in the group *** |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Mar 15, 5:27 am, Barry Margolin <bar...@alum.mit.edu> wrote:
> In article > <6d71ad7a-e06b-48fc-8804-7ffbff43f...@h11g2000prf.googlegroups.com>, > > > > Teo <matteo.co...@gmail.com> wrote: > > Hi again, > > > On Mar 14, 4:29 pm, Teo <matteo.co...@gmail.com> wrote: > > > i am using cpan2rpm to generate RPMS from CPAN perl modules. The > > > script (cpan2rpm is a perl script) uses several non standard file > > > descriptors for output (i.e., saves the descriptors, redirects some > > > output to /dev/null, and restores them). > > > > Now I would like to parse the output of cpan2rpm but it seems that is > > > neither on stdout nor in stderr: > > > > cpan2rpm Class::Accessor > /dev/null 1> /dev/null 2> /dev/null > > > > produces > > > > Generating spec file > > > SPEC: /usr/src/redhat/SPECS/Class-Accessor.spec > > > RPM: /usr/src/redhat/RPMS/noarch/perl-Class- > > > Accessor-0.31-1.noarch.rpm > > > SRPM: /usr/src/redhat/SRPMS/perl-Class-Accessor-0.31-1.src.rpm > > > > How can I store this output to a variable (or file)? > Since this isn't a common behavior, there aren't really any "similar > cases". Any program that does this is ideosyncratic, and the solution > depends on how that program is designed. Hi, sure this is just a solution for this particular problem but the general issue remains: I see the output on the screen so I assume that it is either on stdout or stderr but I cannot redirect it anywhere ... Matteo |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On 2008-03-16, Teo <matteo.corti@gmail.com> wrote:
> > > Hi, > > sure this is just a solution for this particular problem but the > general issue remains: I see the output on the screen so I assume that > it is either on stdout or stderr but I cannot redirect it anywhere ... > > Matteo If you can't redirect it it isn't on stdout or stderr, possibly on /dev/tty. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
In article <3496093d-7485-41cb-9091-c8f6d645d702@s8g2000prg.googlegroups.com>,
Teo <matteo.corti@gmail.com> wrote: .... >Hi, > >sure this is just a solution for this particular problem but the >general issue remains: I see the output on the screen so I assume that >it is either on stdout or stderr but I cannot redirect it anywhere ... > >Matteo Use Expect. Using the "log_file" command allows you to capture *everything* that you see on your terminal (since it logs everything that comes out of your pty), regardless of where (which fd, etc) it comes from. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
2008-03-17, 02:42(+00), Kenny McCormack:
> In article <3496093d-7485-41cb-9091-c8f6d645d702@s8g2000prg.googlegroups.com>, > Teo <matteo.corti@gmail.com> wrote: [...] >>sure this is just a solution for this particular problem but the >>general issue remains: I see the output on the screen so I assume that >>it is either on stdout or stderr but I cannot redirect it anywhere ... [...] > Use Expect. Using the "log_file" command allows you to capture > *everything* that you see on your terminal (since it logs everything > that comes out of your pty), regardless of where (which fd, etc) it > comes from. But it doesn't for the OP's question: have stderr in one file and stderr+stdout in another. And, you'll also have ordering problems with expect if you want to do that has ptys have buffering as well. -- Stéphane |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
In article <slrnftsb63.4ov.stephane.chazelas@spam.is.invalid> ,
Stephane CHAZELAS <this.address@is.invalid> wrote: >2008-03-17, 02:42(+00), Kenny McCormack: >> In article <3496093d-7485-41cb-9091-c8f6d645d702@s8g2000prg.googlegroups.com>, >> Teo <matteo.corti@gmail.com> wrote: >[...] >>>sure this is just a solution for this particular problem but the >>>general issue remains: I see the output on the screen so I assume that >>>it is either on stdout or stderr but I cannot redirect it anywhere ... >[...] >> Use Expect. Using the "log_file" command allows you to capture >> *everything* that you see on your terminal (since it logs everything >> that comes out of your pty), regardless of where (which fd, etc) it >> comes from. > >But it doesn't for the OP's question: have stderr in one >file and stderr+stdout in another. It does. You just have to do some extra handling. >And, you'll also have >ordering problems with expect if you want to do that has ptys >have buffering as well. (I think you have some word order issues here, but intrerpreting as best I can...) That may be true, but Expect will give you whatever you see (or would have seen) on-screen. That's the best anyone can do. |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
2008-03-17, 13:37(+00), Kenny McCormack:
[...] > That may be true, but Expect will give you whatever you see (or would > have seen) on-screen. That's the best anyone can do. Hi Kenny, could you please then post the expect based solution you have in mind to implement the OP's request: save cmd's stdout+stderr in log.txt and stderr in error.txt I don't think that if you manage to do that, you can guarantee that log.txt will have the same thing as you would have had on screen as your solution will have to have cmd's stdout and stderr be streams to different resources (whether they are pipes, ptys or regular files). -- Stéphane |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
2008-03-17, 15:17(+01), pk:
[...] >> 2008-03-17, 13:37(+00), Kenny McCormack: >> [...] >>> That may be true, but Expect will give you whatever you see (or would >>> have seen) on-screen. That's the best anyone can do. >> >> Hi Kenny, could you please then post the expect based solution >> you have in mind to implement the OP's request: >> >> save cmd's stdout+stderr in log.txt and stderr in error.txt > > I think you're replying to the wrong thread. Oops, sorry. Well spotted pk. -- Stéphane |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
Stephane CHAZELAS wrote:
> 2008-03-17, 13:37(+00), Kenny McCormack: > [...] >> That may be true, but Expect will give you whatever you see (or would >> have seen) on-screen. That's the best anyone can do. > > Hi Kenny, could you please then post the expect based solution > you have in mind to implement the OP's request: > > save cmd's stdout+stderr in log.txt and stderr in error.txt I think you're replying to the wrong thread. -- All the commands are tested with bash and GNU tools, so they may use nonstandard features. I try to mention when something is nonstandard (if I'm aware of that), but I may miss something. Corrections are welcome. |
|
![]() |
| Outils de la discussion | |
|
|