简体   繁体   English

如何在多进程中从python调用shell脚本?

[英]How to call a shell script from python in multiprocess?

I want to run a shell script behind, which does a specific job, simultaneously I will wait for the user's input to end the job. 我想在后面运行一个shell脚本,它执行一个特定的工作,同时我将等待用户的输入结束工作。 How can I achieve this? 我怎样才能做到这一点? Here is my example code: 这是我的示例代码:

from subprocess import call

cmd = "internals/applog.sh "
call([cmd])

raw_input("Press Y when you are done: ")

The above code first executes the call statement and only after the app log.sh ends then the following message comes. 上面的代码首先执行call语句,并且只有在app log.sh结束后才会出现以下消息。

Any help in this? 对此有何帮助? how can I make it, when user enters y, the call statement to be aborted? 当用户输入y时,我该怎么做才能中止调用语句?

pid = Popen(["internals/applog.sh",])

while True:
    answer = raw_input("Press Y when you are done: ")
    if answer == 'Y':
        pid.kill()
        break

call() waits for the command to be completed, I think you'd want to use Popen instead: call()等待命令完成,我想你想要使用Popen代替:

from subprocess import Popen

Popen(["internals/applog.sh"])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM