LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   STDIN, STDOUT, STDERROR Redirection for scripting (https://www.linuxquestions.org/questions/programming-9/stdin-stdout-stderror-redirection-for-scripting-830755/)

Sabir_101 09-07-2010 06:13 AM

STDIN, STDOUT, STDERROR Redirection for scripting
 
Hi there,

I'm writing a script to execute bash commands in the PHP CLI. I would like to suppress errors from bash and write my own error message if an error occurs.

So far I have this (assuming log.txt doesn't exist!):

Code:

tac log.txt 2>/dev/null
Which works as expected, tac kicks up an error but the error is suppressed, but when I use this:

Code:

tac < log.txt 2>/dev/null
I get:

Code:

bash: log.txt: No such file or directory
The tac error is suppressed but bash still gives me a dirty error.

Does anyone know how to suppress this?

Guttorm 09-07-2010 06:19 AM

Code:

(tac < log.txt) 2>/dev/null

Sabir_101 09-07-2010 06:21 AM

Much appreciated! Thanks.


All times are GMT -5. The time now is 06:11 PM.