- os.system
- system
External command with system
examples/os/os_system.py
import os command = 'ls -l' exit_code = os.system(command) # $? on Linux/OSX # %ERRORLEVEL% on Windows print(exit_code) exit_code = os.system('ls qqrq') print(exit_code) print(exit_code // 256) exit_code = os.system('ls /root') print(exit_code) print(exit_code // 256)
If you wanted to list the content of a directory in an os independent way you'd use os.listdir('.') or you could use the glob.glob("*.py") function to have a subset of files.