Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python subprocess

import subprocess

#WE USE SUBPROCESS LIBRARY IN PYTHON TO RUN SOME LINUX AND SHELL COMMANDS
#FOR EXAMPLE. 
#LET'S CREATE AN ECHO COMMAND USING PYTHON SUBPROCESS LIBRARY.
subprocess.run("echo Hello World", shell=True)

#OUTPUT:
#Hello World

#TO LIST FILES IN A CURRENT DIRECTORY 
subprocess.run("ls -la"), shell=True)

#OUTPUT: WILL LIST FILES IN THE CURRENT DIRECTORY.

#WITH SUBPROCESS THERE IS NO LIMIT ON HOW YOU INTERACT WITH THE SHELL USING PYTHON
#AS A GATEWAY.
 
PREVIOUS NEXT
Tagged: #python #subprocess
ADD COMMENT
Topic
Name
4+2 =