How do I create a subprocess in Python?

后端 未结 6 1547
孤独总比滥情好
孤独总比滥情好 2021-01-18 09:21

I would like to create a subprocess of a process.

What would be a working example which shows how to accomplish this?

6条回答
  •  被撕碎了的回忆
    2021-01-18 10:13

    Based on user225312's answer, I prepared the below one liner, it may help you to test the subprocess:

    python -c "import subprocess;
    output = subprocess.Popen(['uname', '-a'], stdout=subprocess.PIPE).communicate()[0]; 
    print output"
    

    result like: Linux xxx.xxx.xxx.xxx 3.10.0-957.1.3.el7.x86_64 #1 SMP Thu Nov 29 14:49:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

提交回复
热议问题