Not able to get control back after subprocess.call() in python - python-3.x

I'm creating a thread which is opening another python file using subprocess.call() which is using cmd prompt to run some commands. After running all the commands this cmd doesn't get closed and my main script keeps waiting for this thread to finish. How can I get it closed?

Related

How can I open another console window

I am trying to open a new console terminal from Rust. With the help of documentation, I was capable of starting a terminal in the current terminal window, but not in another one.
For example, imagine I have one folder with two files main.py and bb.py and the following code does the thing I want
import os
os.system("start cmd /K python bb.py")
It opens a new terminal, and in this new terminal the command python bb.py is executed. How can I do this in Rust?

How to check if a script is already running

How do you check if your script is already running to prevent it from running/opening multiple times.
I am aiming for it to either quit and allow the script to open again or stop the new one from running.
Using:
Python 3.8
Windows 10
File type .pyw
Ide: Thonny
I have looked and haven't been able to find a answer.

.exe doesn't run after building from .py [duplicate]

This question already exists:
Can't run script when i convert .py to .exe [closed]
Closed 3 years ago.
I am beginner at python. I have just created a script which includes a Tkinter GUI application. Whenever i run it using cmd it works fine but whenever i tried to create an exe of it using pyinstaller or cx_Freeze it won't run. It just pops up console and terminates within a second.
I think your problem is that using cmd, it starts the program and does not terminate until you close the shell, and the tkinter window stays open, but when you use an exe file, it terminates after all the code is run once, so you should probably have a while loop running preferably forever until the window is closed by you.

How to run a shell which will stop current process? [duplicate]

This question already has answers here:
Make child process spawned with system() keep running after parent gets kill signals and exits
(2 answers)
Closed 3 years ago.
The program processA is a Linux service, launched by "systemctl start processA".
This process will call std::system to run a shell script to upgrade software.
The script will run "systemctl" to stop processA first, then replace some executable files, finally restart processA.
The problem is that when "systemctl stop processA" is executed, the script is also terminated.
How to solve it?
I had tried to run the script file in terminal; it works. So there is not a problem with the script.
//this is how the script is called
int rs = std::system("/usr/bin/update_server.sh upgrade \"/tmp/firmware\" > \"/tmp/upgrade.log\" 2>&1");
systemd will also kill child processes (after all, that's what's usually desired), so you can't do the upgrade from the service.
You can, however create a oneshot service to upgrade the binary that conflicts with the main service. To upgrade, you stop the service, run the upgrade service and then start the service again.

How to execute Python3 script and get the print output in node-red?

I have a node-red server and I want to create automatic processes to run my scripts in node-red, put the (print output) that is coming from the client script.
When I execute the same file through Pycharm, it works and I see the print on the console.
When I execute it through node-red via command line in exec such as:
/usr/bin/sudo /usr/local/bin/python3.7 /Users/mac/Documents/local-node-red3/Client.py
It seems like it is working and sends sudo pass permission to node-red terminal. I give the permissions and initiate the other scripts. But at the end, nothing comes up to the node-red screen.
Note: I added the side bar to show you, somehow I was able to capture the exception thread in node-red for the error. If this is shown here why not the results in the console?
If I go back to Pycharm and execute the client script there, prints start to show up in Pycharm as it is supposed to be. But again, nothing in the node-red side.
I have 5 different scripts in total, 4 of them is executed in Pycharm. I only want to execute the client here and get the output to node-red screen and visualise it in the chart afterwards.
Do I need to write additional function in node-red to read the print statement in order to read the client script output?

Resources