Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: System command silent screen

by uvnew (Acolyte)
on Oct 10, 2010 at 15:48 UTC ( [id://864492]=note: print w/replies, xml ) Need Help??


in reply to Re: System command silent screen
in thread System command silent screen

Many thanks Moritz. I am using Ubuntu. Sorry for being slow (I don't use Perl often), but what should be the actual command line for redirecting the system command screen output?

Replies are listed 'Best First'.
Re^3: System command silent screen
by moritz (Cardinal) on Oct 10, 2010 at 16:05 UTC
    system "$command @arguments >/dev/null 2>&1" and die "...";
    Perl 6 - links to (nearly) everything that is Perl 6.
      Thanks a lot, that's perfect!

        No, it isn't perfect. It invokes an unknown shell with unquoted arguments. That's begging for trouble.

        If you want your script to play safe, fork() manually, then open /dev/null (or even better the return value of File::Spec->devnull()) as STDOUT and STDERR in the child process, then call exec() with a list of program name and arguments. In the parent process, wait() or waitpid() for the PID returned by fork().

        This way, no shell is involved, and all of those nasty quoting problems are magically gone.

        Of course, this requires more typing and more thinking. Alternatively, you can use one of the CPAN modules that wraps open(), fork(), exec(), waitpid(). Look at IPC::Run and IPC::Run3.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://864492]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-24 00:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found