using 2>/dev/null in exec()

Discussion in 'Perl Misc' started by Russ Jones, May 3, 2005.

  1. Russ Jones

    Russ Jones Guest

    If I use an exec() statement with only one parm, like this:

    exec('/some/pgm -parm parm 2>/dev/null');

    everything works fine, and STDERR goes to /dev/null just like I want it to,
    because this form of the call sees the 2> shell metacharacters and passes
    them to the shell for execution.

    But I prefer to use the list method of calling exec() because of the better
    security:

    push(@parms,'-parm','parm','2>/dev/null');
    exec("/some/pgm",@parms);

    Unfortunately, the very reason that I like the list method, that it doesn't
    use the system shell, also makes the "2>/dev/null" part not work, because
    that's not part of the /some/pgm, it's part of the shell.

    Is there a way I can make STDERR go to /dev/null and still use the list
    method of the call?

    Thanks for looking,
    Russ Jones
    Russ Jones, May 3, 2005
    #1
    1. Advertising

  2. Russ Jones

    Guest

    In comp.lang.perl.misc Russ Jones <> wrote:
    > Is there a way I can make STDERR go to /dev/null [...]


    perldoc -f open

    Separate the redirection from the exec and it all falls into place :)
    Chris
    , May 3, 2005
    #2
    1. Advertising

  3. [ No modules here, F'ups trimmed ]


    Russ Jones <> wrote:

    > STDERR goes to /dev/null just like I want it to,



    > But I prefer to use the list method of calling exec()



    > push(@parms,'-parm','parm','2>/dev/null');
    > exec("/some/pgm",@parms);


    > Is there a way I can make STDERR go to /dev/null and still use the list
    > method of the call?



    Let it inherit STDERR from the perl process:

    open STDERR, '>', '/dev/null' or die ...
    push(@parms,'-parm','parm');
    exec("/some/pgm",@parms);


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, May 3, 2005
    #3
  4. Russ Jones

    Russ Jones Guest

    Tad McClellan <> wrote in
    news::

    >> Is there a way I can make STDERR go to /dev/null and still use the list
    >> method of the call?

    >
    >
    > Let it inherit STDERR from the perl process:
    >
    > open STDERR, '>', '/dev/null' or die ...
    > push(@parms,'-parm','parm');
    > exec("/some/pgm",@parms);
    >
    >


    Just what I needed, and it's so obvious that it's easy to see why I missed
    it. Thanks Tad.

    Russ
    Russ Jones, May 5, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    26,616
    Mike Schilling
    Mar 29, 2006
  2. Bo Peng
    Replies:
    13
    Views:
    13,305
    Siemel Naran
    Jul 18, 2004
  3. Hal Vaughan
    Replies:
    11
    Views:
    1,107
    Gordon Beaton
    May 22, 2006
  4. tedsuzman
    Replies:
    2
    Views:
    7,080
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  5. Guillermo Riojas
    Replies:
    0
    Views:
    170
    Guillermo Riojas
    Nov 26, 2010
Loading...

Share This Page