简体   繁体   中英

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. 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.

Any help in this? how can I make it, when user enters y, the call statement to be aborted?

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:

from subprocess import Popen

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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