Using Python to open a shell environment, run a command and exit environment

前端 未结 5 1170
感动是毒
感动是毒 2020-12-19 04:39

I\'m trying to automate a process using python. If I am just in the terminal the workflow looks like:

user:> . /path/to/env1.sh
user:> python somethin         


        
5条回答
  •  无人及你
    2020-12-19 05:27

    You can use subprocess:

    >>> import subprocess
    >>> subprocess.call('python something.py', shell = True)
    

    Or you can use os:

    >>> import os
    >>> os.system('python something.py')
    

    Here is an example (turn on your speakers):

    >>> import os
    >>> os.system('say Hello')
    

提交回复
热议问题