1

I'm running a python script through cmd, that opens a new shell that runs a bash script. the problem is that I also need to kill it...

I've tried using subprocess.kill() subprocess.terminate() and even os.system("taskkill /F /pid "+str(p.pid)) that gives back

SUCCESS: The process with PID 11508 has been terminated.

which didn't happen.

my code goes like this: the relevant python line is

p = Popen(['C:/cygwin64/bin/bash.exe', '-c', '. /etc/profile; /cygdrive/c/Users/user/Desktop/host_manager/ba.sh'], creationflags=CREATE_NEW_CONSOLE)

and ba.sh is

#! /bin/bash
`. /etc/profile`
/home/user/rc64_host_server.exe -in 50001 -out 50002 -d 1 -dsn 14993-0050

the exe is a ssh server that listens.

by the way, when I run

p = Popen('C:/cygwin64/bin/bash.exe', creationflags=CREATE_NEW_CONSOLE)

kill manages to do the job.

how can I kill the subprocess with the script??

  • In what way don't the answers to this question help you: https://stackoverflow.com/q/4789837/1025391 ? – moooeeeep Oct 24 '19 at 11:39
  • do you know what is the process id of the process you want to kill? – rok Oct 24 '19 at 11:39
  • I've tried both os.killpg and psutil.Process but the interpreter said that they do not exist, and also the os.system. what other option did I miss? – Aviran Hazout Oct 24 '19 at 13:47
  • @rok yes, I have a process id, but when I try to kill it with os.system I get a good return but the process still runs – Aviran Hazout Oct 27 '19 at 19:23

0 Answers0