0

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?

1 Answer 1

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.

3
  • i've understood..thanks :) So it is a problem of ncftpput that wrongly sent the output to stderr?
    – Paolo
    Oct 17, 2011 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. Oct 18, 2011 at 0:36
  • ahhhhh ok ok i've totally understood :D thanks a lot!
    – Paolo
    Oct 19, 2011 at 14:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .