Reputation: 1527
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?
Upvotes: 1
Views: 817
Reputation: 20341
pid = Popen(["internals/applog.sh",])
while True:
answer = raw_input("Press Y when you are done: ")
if answer == 'Y':
pid.kill()
break
Upvotes: 2
Reputation: 203286
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"])
Upvotes: 1