0

I'm trying to process multiple videos in a folder and produce results through redirecting their outputs to a text file. When I do this inside the bash script, it doesn't work and doesn't redirect and instead shows on screen. What should I change? How to fix it?

for f in *.mp4
do
  echo "Processing $f file..."
  # take action on each file. $f store current file name
  python myscript.py $f &> ../log-$f.txt 
done
Tina J
  • 4,983
  • 13
  • 59
  • 125
  • 1
    Remove the & before >. By default it should send the stdout to a file. Another option is `tee`.. `python myscript.py $f | tee ../log-$f.txt` – slackmart Nov 26 '19 at 22:16
  • But I also need the stderr to be output. – Tina J Nov 26 '19 at 22:17
  • Use 2>&1, which redirects 2 (stderr) to 1 (stdout), and finally tee will send everything to the file. Something like `python myscript.py "$f" 2>&1 | tee ../log-"$f".txt`. You can replace `| tee` with `>` if you want to. My advice is to try both and see the difference :) – slackmart Nov 26 '19 at 22:20

1 Answers1

1

change this:

python myscript.py $f &> ../log-$f.txt

to this:

python myscript.py "$f" &> ../log-"$f".txt

I didn't check it but it should work, unless you'll have to specify absolute path, but it's just a guess.

Suspended
  • 1,184
  • 2
  • 12
  • 28