Question PyQt5 sending a Ctrl-C command to a running command prompt

salm2s

Honorable
Jul 21, 2017
266
6
10,815
Hi there,
So i have this push button which is connected to a function to run a small .bat file that prints "Hello there"
I also created another push button called "Stop".

Is there a way i can make a function to send a Ctrl-C or a terminate signal to the command prompt?

Thanks,
salm2s
 
Sep 28, 2019
83
7
45
Is there a way i can make a function to send a Ctrl-C or a terminate signal to the command prompt?
Not a good idea.

By button start, you should keep the process handler/instance in you app, and by stop operation, simply kill the process by OS level.

Please mind that Ctrl + C works with some specific TTYs, and it actually send SIGTERM to process. Please mind that process may ignore it(but not by default)

Another option(not really legit) is for asking the process pid when you start it up, later you could ask the OS using kill command

If need more help, you may share some coding you have done so far please.

Hope it helps
 

salm2s

Honorable
Jul 21, 2017
266
6
10,815
Not a good idea.

By button start, you should keep the process handler/instance in you app, and by stop operation, simply kill the process by OS level.

Please mind that Ctrl + C works with some specific TTYs, and it actually send SIGTERM to process. Please mind that process may ignore it(but not by default)

Another option(not really legit) is for asking the process pid when you start it up, later you could ask the OS using kill command

If need more help, you may share some coding you have done so far please.

Hope it helps
Ah ok, so i should just let the user click the 'x' rather than a stop button?
 
Sep 28, 2019
83
7
45
Ah ok, so i should just let the user click the 'x' rather than a stop button?
No no no, please mind, if you kill a parent process(let say your qt app), so it might not kill its child process, so even if you kill your qt process, the command/bat file could continue its process.

You may please share some code, how do you use QT? C/C++? python?
How do you run that cmd process?

When you start a process(run a bat for example), OS gives the parent app(QT app here)a handler that points out to the child process.
Anytime later, parent, is able to kill the child process peacefully or by-force.
 

salm2s

Honorable
Jul 21, 2017
266
6
10,815
No no no, please mind, if you kill a parent process(let say your qt app), so it might not kill its child process, so even if you kill your qt process, the command/bat file could continue its process.

You may please share some code, how do you use QT? C/C++? python?
How do you run that cmd process?

When you start a process(run a bat for example), OS gives the parent app(QT app here)a handler that points out to the child process.
Anytime later, parent, is able to kill the child process peacefully or by-force.
I meant like when the command prompt opens, the user just clicks the red x. Btw this is for windows.
 
Sep 28, 2019
83
7
45
How can I run a command on Linux in python code to start a new terminal window, cd to a file in the folder and run a application?
Maybe you don't need running a command line to run another process. not logical(unless you would run a batch of commands).

You could ask the OS to run the target app(in target path) directly without any middle-cmd
 

TRENDING THREADS