LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 08-17-2007, 09:32 AM   #1
stankelay
LQ Newbie
 
Registered: Aug 2007
Posts: 3

Rep: Reputation: 0
How to completely stop terminal output?


Hi,
In a shell script, I would like to quietly execute a command which produces long outputs.

Basically, I've tried to use the > (redirection) operator but only parts of this command output were logged to the file. These parts are all the "echo" contained in the command I want to execute. This command contains calls to C programs producing output that is always visible in the terminal.

I also tried to play with stty but without any success. I thought maybe the -cread option was what I need but it seems not to be accessible on my platform (ubuntu)

So my question is simple : how can I completely stop the terminal output while executing my command?
 
Old 08-17-2007, 09:52 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
seems like some of the stuff is also going to stderr.

you have already re-directed stdout to a file but now you need to re-direct stderr to stdout.

google(re-direct stderr) = http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html

Last edited by schneidz; 08-17-2007 at 09:54 AM.
 
Old 08-17-2007, 10:37 AM   #3
stankelay
LQ Newbie
 
Registered: Aug 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Yes you're right!
So I just need to do :

$ command 2> logfile.txt

Thanks!
 
Old 08-17-2007, 12:38 PM   #4
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Using &> should get it all in one place.
 
Old 08-19-2007, 08:37 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
2 options:

stdout & stderr in same file:
cmd >cmd.log 2>&1

separate files
cmd >cmd.log 2>cmd.err

your choice, but (1) is easier to debug usually.

you can also put it safely in the background with
nohup <above stuff> &

& - put in background
nohup - allow user to logout without process terminating
 
Old 08-20-2007, 05:08 AM   #6
stankelay
LQ Newbie
 
Registered: Aug 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
stdout & stderr in same file:
cmd >cmd.log 2>&1
This one is what I really need.

Thanks !

Last edited by stankelay; 08-20-2007 at 06:29 AM.
 
Old 08-20-2007, 05:34 AM   #7
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Quote:
cmd >cmd.log 2>&1
Just to clarify this a bit, the first redirection (>cmd.log) redirects stdout (1) output ("normal things", like echos etc.) to the given file, and the second (2>&1) redirects stderr (2) to where ever stdout is going (&1 means "where 1 [stdout] goes"). For this to work properly in this case, stdout has to be redirected first, and stderr second (read: the one that is redirected with & is redirected second, to make it go right), because if it was done the other way around, stderr would go to terminal (where stdout usually goes) and stdout to the file; this is because the shell interprets these from left to right.

Hope it clarified it a bit. It's also possible to direct outputs to variables and then use those variables in shell scripts, for example. It's not difficult either, but slightly more complicated than "normal" redirecting. Usual sometimes, though!

Last edited by b0uncer; 08-20-2007 at 05:36 AM.
 
  


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
Redirect terminal output to file AND terminal shan Linux - General 3 09-29-2006 08:36 AM
How to stop a command or start over, in a terminal royeo Linux - Newbie 6 08-12-2006 01:21 PM
Stop gnome terminal startup notification manobes Linux - Software 0 11-04-2004 09:42 AM
How to stop terminal escape sequences ? Mike Davies Linux - Newbie 1 08-08-2004 11:37 AM
Completely Transparent Terminal chrisk5527 Linux - General 8 05-20-2004 05:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:26 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