LinuxQuestions.org
Review your favorite Linux distribution.
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 06-07-2007, 05:33 PM   #1
milindlokde
Member
 
Registered: Apr 2007
Location: Mumbai, India
Distribution: Fedora, ubuntu
Posts: 119

Rep: Reputation: 21
Question aplay -l > message,txt creates empty file


Why am I unable to redirect the output of the command aplay-l to a text file. The command is giving its output on the display device. When I redirect its output to text file
Code:
aplay -l > message.txt
It creates an empty file.
Are there any other such commands? How can they be created?
 
Old 06-08-2007, 10:16 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,118

Rep: Reputation: 218Reputation: 218Reputation: 218
Maybe try:
aplay -l &> message.txt

If the program writes messages as "errors" this would help.
 
Old 06-16-2007, 10:17 AM   #3
milindlokde
Member
 
Registered: Apr 2007
Location: Mumbai, India
Distribution: Fedora, ubuntu
Posts: 119

Original Poster
Rep: Reputation: 21
Smile

Quote:
Originally Posted by Guttorm
Maybe try:
aplay -l &> message.txt

If the program writes messages as "errors" this would help.
Thanks, indeed the program writes the message as errors. The command worked. I found two more methods of getting the output in the file in the process:
1)Copy & Paste the output in gui mode from terminal window in any text editor.
2)Use script command which records all standard inputs as well as error outputs.
 
Old 06-16-2007, 11:57 PM   #4
dugas
Member
 
Registered: Jul 2004
Location: louisiana
Distribution: fedora 4/kubuntu
Posts: 116

Rep: Reputation: 15
Redirect standard output and error output

Code:
aplay -l >> message.txt 2>&1
Will redirect both standard output (stdout) and error output (stderr) to a file.
 
Old 06-23-2007, 09:27 AM   #5
milindlokde
Member
 
Registered: Apr 2007
Location: Mumbai, India
Distribution: Fedora, ubuntu
Posts: 119

Original Poster
Rep: Reputation: 21
Quote:
Originally Posted by dugas
Code:
aplay -l >> message.txt 2>&1
Will redirect both standard output (stdout) and error output (stderr) to a file.
That works too! But why is '2' and '&1' written after the file name and not before it. And how does it work after the file name. What is it's syntax.
 
Old 06-24-2007, 01:46 PM   #6
dawkcid
Member
 
Registered: May 2007
Location: UK
Distribution: LFS,Slackware,Slamd64,NetBSD
Posts: 102

Rep: Reputation: 15
Code:
aplay -l >> message.txt 2>&1
There are two redirections going on here. First, redirect stdout to a file '>> message.txt', then redirect stderr to stdout '2>&1' (which is now directed to the file).

The key to understanding how it works it to remember that the redirection happens at the point it is specified. So, if you put the '2>&1' before the '>> message.txt', then you are redirecting stderr to stdout (which is still connected to the terminal), then you are redirecting stdout to the file (that this does not affect stderr, which remains connected to the terminal).
 
  


Reply


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
How can read from file.txt C++ where can save this file(file.txt) to start reading sam_22 Programming 1 01-11-2007 05:11 PM
LXer: Piracy creates jobs, FOSS creates opportunities LXer Syndicated Linux News 0 11-02-2006 11:33 AM
Postfix: why is 'Return-Path' of bounce message empty Chowroc Linux - Networking 1 12-28-2005 03:52 AM
How to convert a txt file to be a db file in Redhat linux 9? winnie Linux - Newbie 3 06-27-2003 08:33 AM
ez way to find the process that creates a file? Griffon26 Linux - General 2 08-20-2002 03:36 PM


All times are GMT -5. The time now is 08:21 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration