0

I'm having some problems with combining python, time and tee.

I have a script script.sh which contains following line:

{ time python extractPassRate.py -i DataPaths/background.list -o PassRates/background.csv ; } 2>&1 | tee log.log

However, when I do:

source script.sh

The terminal just hangs.

Interestingly when i replace that line with:

{ time python extractPassRate.py ; } 2>&1 | tee log.log

(that is, if I remove the python script arguments) or

{ time python extractPassRate.py -i DataPaths/background.list -o PassRates/background.csv ; } 2>&1

(not saving to log.log)

The script works.

Is there something wrong with the first line?

Davide Porzio
  • 159
  • 1
  • 10

1 Answers1

0

Googling around, I found the solution here, by Matthew Alpert: How to redirect output to a file and stdout

It seems that was due to a buffering problem.

Matthew's answer says:

The program unbuffer, part of the expect package, will solve the buffering problem. This will cause stdout and stderr to write to the screen and file immediately and keep them in sync when being combined and redirected to tee. E.g.:

$ unbuffer program [arguments...] 2>&1 | tee outfile

That worked for me

Community
  • 1
  • 1
Davide Porzio
  • 159
  • 1
  • 10