Skip to content

Latest commit

 

History

History
20 lines (17 loc) · 591 Bytes

shell-in-python.md

File metadata and controls

20 lines (17 loc) · 591 Bytes
layout element title language
page
notes
Shell from inside Python
Python

Everything you can do in the shell you can do using Python. The two key modules for doing so are:

  • os, which is easy import os os.system("ls -l -a")

  • subprocess, which is "best"

      import subprocess
      subprocess.call(["ls"])
      subprocess.call(["ls", "-l"])
      directory_list = subprocess.check_output(["ls", "-l"])
      directory_list = subprocess.os.listdir('.')