Hello linux experts, below code in a perl script throws error message when the particular job has not started yet. Is there a way to redirect the error output to somewhere else. Basically I dont want to see error/warning msgs in the output. I want the command to execute silently... ``` my @lines = `bjobs -l $job_id`; ```
There are ways to redirect stderr, but it has been a while so I don't know them off hand. However, that is what you want to look into. Redirecting stderr.
Since you're calling some bash script/program (in between the two backticks), you can use the bash way of redirecting output. To get rid of any message that's printed on stderr, try `bjobs -l $job_id 2> /dev/null`. What it'll do is redirect stderr (stream 2) to /dev/null, which in this case is just a sink that discards the output. Btw, how did you do the code formatting in your post?
i tried that it didnt work in my shell (tcsh). it is working only when I change my shell to ksh or bash. but my default shell is tcsh to which all other programs are tweaked. i have tried bjobs -l $job_id >& /dev/null, but it is redirecting stdout also, actually i wanto capture output if theres any, and i want it redirect only stderr...
there doesnt seem to be a way in tcsh to do this :(
Ah! tsch. Did you look at the man page? "The shell cannot presently redirect diagnostic output without also redirecting standard output, but `(command > output-file) >& error-file' is often an acceptable workaround. Either output-file or error-file may be `/dev/tty' to send output to the terminal."
Join our real-time social learning platform and learn together with your friends!