xxxxxxxxxx
import subprocess
output = subprocess.check_output('pidstat -p ALL'.split(' '), stderr=subprocess.STDOUT, universal_newlines=True)
print(output)
xxxxxxxxxx
In the file job.sh, put this
#!/bin/sh
python python_script.py
Execute this command to make the script runnable for you : chmod u+x job.sh
Run it : ./job.sh
xxxxxxxxxx
import subprocess
process = subprocess.Popen(['echo', 'hi'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = process.communicate()
print(out) # hi
print(err) # None
xxxxxxxxxx
import subprocess
# Example command that you want to run
command = "ls -l"
# Run the command using subprocess.call() function
subprocess.call(command, shell=True)
xxxxxxxxxx
import subprocess
# Replace 'script.sh' with the actual name/path of your bash script
script_path = '/path/to/script.sh'
# Run the bash script
result = subprocess.run(['bash', script_path], capture_output=True, text=True)
# Print the output of the script
print(result.stdout)
xxxxxxxxxx
import subprocess
subprocess.call(["./shell.sh"])
# Make sure that "shell.sh" has "+x" permissions
xxxxxxxxxx
# First, install python or python3...
sudo apt-get install python
#or
sudo apt-get install python3
# Then, run your python file...
python /path-to-file/pyfile.py #or
python3 /path-to-file/pyfile.py
#Example
python /home/person/randomfile.py #or
python3 /home/person/randomfile.py
# Hope this helped :)