Mitja
Mitja

Reputation: 309

Bash: echo from command while it's executing

I want to see the entire output (not just the return value) of a script while it's executing via bash, like this:

#!/bin/sh    
cmd="$(script.py $arg)"

script.py prints multiple lines while executing, but I'm unable to see them in bash. Is there a way to maybe pipe the output to stdout?

Upvotes: 1

Views: 266

Answers (2)

user904990
user904990

Reputation:

this will display each line "produced" by your script while it is running:

while read line; do echo $line; done < <(script.py $arg 2>&1)

it will also, as suggested in the post above, redirect stderr to stdout

Upvotes: 1

Vaughn Cato
Vaughn Cato

Reputation: 64308

Perhaps it is being output to stderr. Try this:

#!/bin/sh    
cmd="$(script.py $arg 2>&1)"

Upvotes: 1

Related Questions