1

I can list the root directory using a script file and command line.

%%writefile ShowDir.py
import os
import sys
from sys import argv
DIR = argv[1]
show = os.listdir(DIR)
print show

Then I ran in the terminal:
!echo mypassword | sudo -S python ShowDir.py /root
It worked, but I want a more graceful approach.
I also tried:
This will run files, make directories, remove files directories, but for some reason will not LIST them.

import os, subprocess
ret = subprocess.check_call("echo mypassword | sudo -S ls /root",   shell=True) 
ret

It just returned a 0, no directory listing

JackNorthrup
  • 343
  • 3
  • 11
  • Possible duplicate of [using sudo inside jupyter notebook's cell](https://stackoverflow.com/questions/44996933/using-sudo-inside-jupyter-notebooks-cell) – user3483203 Mar 30 '18 at 09:40
  • 1
    No, It is not. I can use sudo in a Jupyter Notebook all the time. I even showed an example. But, for some reason, it will not list the files in /root . Try to list files with the same command for example " ls /root/ " , does not work. I used the password.password() and am familiar with it. Listing directories does not work. – JackNorthrup Mar 31 '18 at 00:37

0 Answers0