1

I got a problem with redirecting output to file.

I'm writting script in bash.

Here is the code:

function getParameters
{
       echo `avprobe "$TMP_CATALOGUE/$FILE_NAME"` >> "$TMP_CATALOGUE"/file_parameters.txt
}

unfortunately, only thing i get in file_parameters.txt is:

# avprobe output

It doesn't throw any errors. When i write "avprobe file_name" in terminal, it works properly.

How should i write it to make it work?

Thank you in advance.

Kate
  • 21
  • 3
  • There's no need to wrap a command in `echo \`...\`` to send its output somewhere. Just `command >> file` works the same (unless you want to squash all whitespace in the output or something). When you run that command do you get output to your screen instead of the file? – Etan Reisner Sep 24 '14 at 01:16
  • Yes, it gives output to screen. I'm sorry for not mentioning that earlier... – Kate Sep 24 '14 at 01:22
  • Sounds like it uses standard error (`stderr`) and not standard output (`stdout`). Try `>> file 2>&1`. – Etan Reisner Sep 24 '14 at 01:28
  • possible duplicate of [bash: redirect and append both stdout and stderr](http://stackoverflow.com/questions/876239/bash-redirect-and-append-both-stdout-and-stderr) – Etan Reisner Sep 24 '14 at 01:45

1 Answers1

0

avprobe seems to output its info to stderr, not stdout.

What you probably want to do

Check this out:

avprobe -of json -show_format -show_streams "$TMP_CATALOGUE/$FILE_NAME" >> "$TMP_CATALOGUE"/file_parameters.json

However, you can also...

Redirect stderr with 2>> instead of the stdout with >>:

echo `avprobe "$TMP_CATALOGUE/$FILE_NAME"` 2>> "$TMP_CATALOGUE"/file_parameters.txt
danuker
  • 861
  • 10
  • 26