Hi Jim, On Tue, 19 Jul 2011 16:22:14 -0700 Jim Gibson <jimsgib...@gmail.com> wrote:
> On 7/19/11 Tue Jul 19, 2011 12:14 PM, "Tessio Fechine" <oiss...@gmail.com> > scribbled: > > > Hello, > > I have a subroutine that uses useradd to create accounts > > > > -- > > @cmd = ('useradd', '-m', $account); > > my $result = system @cmd; > > -- > > > > but when useradd fails, I need to stop it from sending the error message to > > STDER. > > Is it possible with system? > > You can use a shell process to discard STDERR messages (untested): > > my $cmd = "useradd -m $account 2> /dev/null"; > my $result = system($cmd); > The problem with interpolating strings into shell commands like that is that someone may put malicious code in it: my $account = 'foo; rm -fr / '; so be careful - see: http://shlomif-tech.livejournal.com/35301.html (Code/Markup Injection and Its Prevention ). Regards, Shlomi Fish > You could do the same by writing a shell script to redirect STDERR and call > that from your Perl program. > > You can also use the IPC::Open3 module to capture STDERR. See 'perldoc > IPC::Open3' for examples. > > > > -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Apple Inc. is Evil - http://www.shlomifish.org/open-source/anti/apple/ An apple a day keeps the doctor away. Two apples a day will keep two doctors away. — one of Shlomi Fish’s relatives Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/