Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-07-2010, 06:13 AM   #1
LQ Newbie
Registered: Sep 2010
Posts: 3

Rep: Reputation: 0
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!):

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:

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

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?
Old 09-07-2010, 06:19 AM   #2
Senior Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,293

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
(tac < log.txt) 2>/dev/null
1 members found this post helpful.
Old 09-07-2010, 06:21 AM   #3
LQ Newbie
Registered: Sep 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Much appreciated! Thanks.


bash, redirection

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
tar, stdin or stdout evil_empire Linux - Newbie 3 06-20-2009 06:43 PM
Details of stdin and stdout pixellany Linux - Newbie 1 01-11-2006 01:21 PM
stdout stdin Furlinastis Linux - Newbie 3 08-11-2005 11:00 PM
stdout & stderror output nevx Linux - Newbie 1 05-03-2005 06:56 AM
stdin -> port -> stdout acid_kewpie Linux - Networking 5 04-12-2002 06:01 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:28 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration