PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Redirection and additional file descriptors
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Redirection and additional file descriptors

Réponse
 
LinkBack Outils de la discussion
Vieux 14/03/2008, 16h29   #1
Teo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Redirection and additional file descriptors

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
  Réponse avec citation
Vieux 14/03/2008, 16h32   #2
Teo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirection and additional file descriptors

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
  Réponse avec citation
Vieux 15/03/2008, 05h27   #3
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirection and additional file descriptors

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 ***
  Réponse avec citation
Vieux 16/03/2008, 21h33   #4
Teo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirection and additional file descriptors

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
  Réponse avec citation
Vieux 16/03/2008, 23h20   #5
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirection and additional file descriptors

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.
  Réponse avec citation
Vieux 17/03/2008, 03h42   #6
Kenny McCormack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirection and additional file descriptors

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.

  Réponse avec citation
Vieux 17/03/2008, 09h34   #7
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirection and additional file descriptors

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
  Réponse avec citation
Vieux 17/03/2008, 14h37   #8
Kenny McCormack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirection and additional file descriptors

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.

  Réponse avec citation
Vieux 17/03/2008, 14h53   #9
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirection and additional file descriptors

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
  Réponse avec citation
Vieux 17/03/2008, 15h09   #10
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirection and additional file descriptors

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
  Réponse avec citation
Vieux 17/03/2008, 15h17   #11
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Redirection and additional file descriptors

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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h12.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18268 seconds with 19 queries