I want to pipe the output file from the command line audio tool SoX into the email tool mutt.

What I want to do is something akin to this:

sox /Users/someUser/Desktop/input.mp3 output.mp3 | mutt -s "someSubject" -a [output-from-sox] some@recipient.com

The thing I don't know how to do is wrapped in square brackets.

I'm a UNIX novice so any hints would be highly appreciated.

  • You don't mean sox /Users/someUser/Desktop/input.mp3 output.mp3 ; mutt -s "someSubject" -a output.mp3 some@recipient.com do you? You want to send the command line output? – Daniel Beck May 17 '11 at 7:56
  • I want sox to output the mp3-file and mutt to email that file. I don't know if my pipe approach is the right way to do this :S – timkl May 17 '11 at 8:08
  • Since your sox call writes output.mp3, why don't you just use that one like I suggested and delete it after sending? In case sending fails or something like that, you'll still have the file to try again. – Daniel Beck May 17 '11 at 8:09
  • 1
    Instead of using ; to separate the commands, use && so that the second command only runs if the first one was successful. – Majenko May 17 '11 at 8:11
  • 1
    It's worth to add that common practice is denoting stdin/stdout as single dash -, whenever input/output file arguments are considered. See example in cat(1) manpage for instance. – przemoc May 17 '11 at 10:31

A pipe in a Unix-like operating system is for running one program, taking its standard output (which would otherwise go to the screen) and using it as input to another program (in place of its standard input which would normally come from the keyboard).

It seems like what you want to do is have one program output to a file, and then have another program use the file as input. You don't need a pipe for that.

To run one program after another one finishes, all on one command line, use ;. For example:

sox /Users/someUser/Desktop/input.mp3 output.mp3 ; mutt -s "someSubject" -a output.mp3 some@recipient.com

Unix command line programs output an "exit status" or "return code". Most programs output 0 to indicate that they did their thing successfully, or some other value if there was a problem. If your first command is like this, use && in place of ; to only run the second command if the first one was successful. For example:

sox /Users/someUser/Desktop/input.mp3 output.mp3 && mutt -s "someSubject" -a output.mp3 some@recipient.com
  • Really helpful explanation, thx a bunch! :) – timkl May 17 '11 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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