Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intermediate bash output in Jupyter notebook

When I run this in terminal:

cd 1st_flask_app_1/
python3 app.py

I get the output:

 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

When I try to run the same command in a Jupyter notebook with the cell magic %%bash, I get no printed output, but the web app still starts up and I can visit it. If I then stop the cell I get the output:

Process is interrupted.

So it looks like the Jupyter notebook with %%bash cell magic is printing final command outputs, but not intermediate outputs. Is there any way to also print the intermediate outputs?

like image 393
Austin Avatar asked Mar 14 '26 20:03

Austin


1 Answers

For some reason it looks like your stdout/stderr are not properly attached to your bash...

Could you try to redirect your command stdout and stderr to a log file in append mode?

python3 app.py >> application.log 2>&1

or you could also pipe it with tee

python3 app.py 2>&1 | tee -a application.log

I hope this helps you!

like image 80
Allan Avatar answered Mar 17 '26 02:03

Allan