Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get output of OS command from Jupyter notebook?

I am running Jupyter notebook on a server (python 3).

Want to see output of OS command (any OS command - this is just example):

output = os.system("pwd")

When I do print of it:

print (output)

Response is 0.

How to get a simple output (like in CLI)?

Thanks.

like image 366
Joe Avatar asked May 10 '19 13:05

Joe


2 Answers

Just found it on internet and wanted to post.

It needs to be:

print(os.popen('ls').read())

(or any other OS command).

This works fine.

like image 175
Joe Avatar answered Oct 17 '22 08:10

Joe


import os

print(os.getcwd())
print(os.system("pwd"))

But this question is a duplicate: how to show current directory in ipython promp

like image 43
Fabrizio Avatar answered Oct 17 '22 07:10

Fabrizio