import subprocess cmd = "ps -ef | grep script.py | awk '{print $1,$2,$3,$4}’” stdoutdata = subprocess.getoutput(cmd) print("stdoutdata: " + stdoutdata.split()[0])