LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-04-2013, 04:07 PM   #1
MrName
LQ Newbie
 
Registered: Jun 2013
Posts: 3

Rep: Reputation: Disabled
Eliminating Stdout and Stderr of Program Receiving EOF Input


Hello all, first time posting here, but spent a lot of time reading the forums. Right now, I am working on a BASH script in which a program is being called, and receiving input via EOF redirection, like so:

Code:
/usr/bin/program << EOF

.....data.....

EOF
This is working just fine, but I want to make the output silent. No matter where I append '> /dev/null 2>&1' I cannot get rid of the stdout or stderr of the actual program being called. It generally causes an error, or has no effect. Is there a way to properly redirect the stdout/stderr of this program? I have tried every possible combination. Any help is greatly appreciated! Thank you!
 
Old 06-04-2013, 04:14 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
It should work like this:

Code:
/usr/bin/program << EOF >/dev/null 2>&1

.....data.....

EOF
The program has three redirections defined for it. stdin is the heredoc, stdout is /dev/null, and stderr is set to the same place as stdout, also /dev/null.

If that doesn't work for you, and I can't see how it wouldn't, please show us what it's really doing in more detail.

Another possibility is to wrap the whole thing in a program group, function, or subshell and redirect that.
Code:
{
/usr/bin/program << EOF

.....data.....

EOF
} >/dev/null 2>&1
Edit: see here for more on how redirections work:
redirections and file descriptors explained

Last edited by David the H.; 06-04-2013 at 04:15 PM.
 
1 members found this post helpful.
Old 06-04-2013, 04:19 PM   #3
MrName
LQ Newbie
 
Registered: Jun 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Dude, that was amazingly fast, and a great explanation! Trying right now, and will update this thread. Thank you very much.
 
Old 06-04-2013, 04:22 PM   #4
MrName
LQ Newbie
 
Registered: Jun 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Smile

Answer 1 worked like a charm! Thank you very much, not sure how I missed that. You rock!
 
  


Reply



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
[SOLVED] Re-directing stdin, stdout, stderr for program run as fork()/execl() AndrewBS42 Programming 3 11-26-2010 08:35 AM
[SOLVED] How to get stderr and stdout of a program into separate env variables? 10110111 Linux - Software 2 05-20-2010 06:17 AM
Can't seem to catch some output from a program - not stdout or stderr. uhh.. help? BrianK Programming 2 01-30-2010 11:53 AM
stdout,stderr makes program crash surfchen Linux - Newbie 3 03-11-2008 05:27 AM
redirecting stdout to /dev/null and stderr to stdout? Thinking Programming 1 05-18-2006 02:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:45 AM.

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