1import subprocess
2subprocess.run(["bash", "testShell.sh"])
3#we don't have to give full path to the shell script. It always execute from the current directory
4
5#As a rule of thumb, you need to separate the arguments based on space,
6#for example ls -alh would be ["ls", "-alh"], while ls -a -l -h,
7#would be ["ls", "-a", -"l", "-h"]. As another example,
8#echo hello world would be ["echo", "hello", "world"],
9#whereas echo "hello world" or echo hello\ world would
10#be ["echo", "hello world"].
11
12#Another example.
13list_files = subprocess.run(["ls", "-l"])
14print("The exit code was: %d" % list_files.returncode)
1import subprocess
2process = subprocess.Popen(['echo', 'More output'],
3 stdout=subprocess.PIPE,
4 stderr=subprocess.PIPE)
5stdout, stderr = process.communicate()
6stdout, stderr
7
1write python and press enter in terminal.
2
3A Python Prompt comprising of three greater-than symbols >>> appears.
1# First, install python or python3...
2sudo apt-get install python
3#or
4sudo apt-get install python3
5
6# Then, run your python file...
7python /path-to-file/pyfile.py #or
8python3 /path-to-file/pyfile.py
9#Example
10python /home/person/randomfile.py #or
11python3 /home/person/randomfile.py
12
13# Hope this helped :)