using 2>/dev/null in exec()

R

Russ Jones

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
 
C

chris-usenet

In comp.lang.perl.misc Russ Jones said:
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
 
T

Tad McClellan

[ No modules here, F'ups trimmed ]


Russ Jones said:
STDERR goes to /dev/null just like I want it to,

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


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);
 
R

Russ Jones

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top