Python subprocess

How do you call a script written in another language in Python?

You can use the subprocess module.


Let’s say you have the bash script

echo Hello, world!

In your Python script, use

import subprocess["bash", ""])

If isn’t available (Python <3.5), use instead:["bash", ""])

When you run your Python script in your command-line:

$ python
Hello, world!


To get the output of the script, use subprocess.Popen to get the process:

import subprocess

proc = subprocess.Popen("bash", shell=True, stdout=subprocess.PIPE)

Then read stdout with Popen.communicate:

outs, errs = proc.communicate()

Alternatively, you can use

outs =

Decode the binary and print the string:



Please support this site and join our Discord!