LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   aplay -l > message,txt creates empty file (http://www.linuxquestions.org/questions/programming-9/aplay-l-message-txt-creates-empty-file-560047/)

milindlokde 06-07-2007 05:33 PM

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?

Guttorm 06-08-2007 10:16 AM

Maybe try:
aplay -l &> message.txt

If the program writes messages as "errors" this would help.

milindlokde 06-16-2007 10:17 AM

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.

dugas 06-16-2007 11:57 PM

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.

milindlokde 06-23-2007 09:27 AM

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.

dawkcid 06-24-2007 01:46 PM

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).


All times are GMT -5. The time now is 09:49 AM.