I'm trying to run an executable file called CDQ.exe (which is supposed to create a text file) from within a python script. I'm using os.system(CDQ.exe) to run it. When I start the python script, the program freezes upon the os.system() call. I also don't get the text file. When I opened the task manager, I found CDQ was still running, and it kept running until I ended it.
When I try to run the CDQ.exe from the windows file browser by clicking it twice, the program appears for a couple of seconds in the task manager, then it closes, and my text file appears.
The executable file was created from c++ qt, and I'm using windows.
Does anyone know what's going on?
Related
I created a python file where an event loop is running.
During this event loop, pressing certain hotkeys causes interaction with another app.
If I open the file and run it through PyCharm, it works.
If I run the file in a terminal or as a .py file, the code exits prematurely for some reason so I have to run it with the python -i command or add input() at the end of the code so that the event loop keeps running for the hotkeys to work. Is there a reason why that happens?
Now I would like to autostart this file every time Windows runs. In theory it should be easy:
Change it to .pyw and run it with pythonw.
However, if I do that and click on the file to execute, it doesn't work. No idea what is happening in the background.
If I run the file in a terminal like this: python main.pyw
the script is executed in the terminal, I can see it and the hotkeys work.
Why is .pyw not working for me here? What other alternative do I have to run the file in the background so that I can always use the hotkeys whenever I boot Windows?
I have a GUI based.exe, which I made using Python auto-py-to-exe (one folder method), and I want the application to run up after every 10 minutes or so.
It is working when I click on it manually.
I have tried using task scheduler in windows to do that, but it is not exactly executing the application as I cannot see anything on screen. Any ideas how to do it?
Not answering directly the question but maybe still solving your problems. To run python scripts on schedule i usually write a .bat script that gets executed by task scheduler.
The bat script has to have the full length python path for the invocation and the full path of the .py file.
I think it's possible to use the same strategy to run exe files, so you could try using a .bat that targets your exe instead of targetting the exe directly in the task scheduler.
I have written a python program that periodically runs with ApScheduler package. The .pyw file runs in the background, but when I restart the PC the program doesn't continue running.
What can I do to run a code automatically in startup a windows 10 pc?
You should consider putting your python file to the Startup folder.
Click Win+R at the same time on your keyboard
Type shell:startup
Drag and drop your python file onto the folder that opened.
Note: I reccomend to put a shortcut of your python file for easier editing.
Is it possible to make a program in Python that, when run, does not actually open any window (including command prompt)?
For example, opening the program would appear to do nothing, but in reality, the program is running in the background somewhere.
Thanks!
Are you running the python program by double clicking *.py file in Windows?
Then, rename the *.py file to *.pyw.
Run it with pythonw.exe instead of python.exe.
I am trying to open a file through python that once it is open takes you to a GUI. The link works fine when i just click on it and python seems to locate the file and open it, but the GUI doesn't appear. Please help. This is whay i have been using.
import subprocess
subprocess.Popen("C:/full/path")
I get no track back errors, but the GUI doesn't appear. Thoughts of how I can get it to appear, or what the problem might be?
Thanks
The file you're trying to 'start' is a cmd script. Use this code:
subprocess.Popen("cmd.exe /k C:\full\path\to\file.cmd")
.cmd files are not executable by themselves - you need to invoke cmd.exe to execute them. This is also what windows does when you double-click the file on the desktop.