Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Let's explain you my doubt.
We all know that >& is shell syntax for "fold a file descriptor into another".
So 2>&1 means that i want to redirect stderr to the stdin, this is simple and clear :)
The thing that i don't understand is this (let explain it with an example)

ncftpput -u $user -p $pass $host $remote_dir $local_file | zenity --text-info --title "Putting files..." --width 600 --height 300

The code above doesn't works...but this works perfectly:

ncftpput -u $user -p $pass $host $remote_dir $local_file 2>&1 | zenity --text-info --title "Putting files..." --width 600 --height 300

I don't undestrand why if i put 2>&1 the redirection to zenity work and if i don't write 2>&1 redirection doesn't works. Why?

share|improve this question

1 Answer 1

By convention, applications produce output on two file descriptors: 1 (stdout) and 2 (stderr). The pipe feature of the shell redirects the stdout of one process to the stdin of another. This way, applications can separate out error or status messages from their normal output and still be usable when piping their output.

It seems that the output you want to pipe to zenity is being sent to stderr. In your second command line, the 2>&1 part says to redirect all output ncftpput sends to stderr to stdout. This causes it to be piped to zenity.

share|improve this answer
    
i've understood..thanks :) So it is a problem of ncftpput that wrongly sent the output to stderr? –  Paolo Oct 17 '11 at 17:12
    
As I said, it isn't uncommon for command line applications to print status messages to stderr. So I would hesitate to describe the behaviour of ncftpput as wrong. –  James Henstridge Oct 18 '11 at 0:36
    
ahhhhh ok ok i've totally understood :D thanks a lot! –  Paolo Oct 19 '11 at 14:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.