Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python run system commands

import subprocess

def run_cmd(cmd, verbose=False, *args, **kwargs):
	"""
    Run system command as a subprocess
    """
    process = subprocess.Popen(cmd, 
                               stdout = subprocess.PIPE,
                               stderr = subprocess.PIPE,
                               text = True,
                               shell = True)
    std_out, std_err = process.communicate()
    if verbose:
        print(std_out.strip(), std_err)

run_cmd('echo "Hello, World!"', verbose = True)
Source by www.scrapingbee.com #
 
PREVIOUS NEXT
Tagged: #python #run #system #commands
ADD COMMENT
Topic
Name
5+8 =