I would like to run the specific commandline application:
ffmpeg -i video.mp4 audio.mp3
I'm running the command through a GUI, and when the console window doesn't exist, the ffmpeg process is running in a new cmd window.
Testers find the "black window that appears" scary and not userfriendly.
How can I run the application without any visible window coming up? os.system(), subprocess.Popen() and subprocess.call() all do launch the cmd window.
If it matters, I'm using pyqt4 and py2exe. I'm targeting Windows OS users.
This recipe at ActiveState may solve your problem:
http://code.activestate.com/recipes/409002/
Slight changes are required for Python 2.7. See How do I eliminate Windows consoles from spawned processes in Python (2.7)?
Launch ffmpeg from the START command. If you use the /B switch, no command window will be shown.
Use subprocess.Popen (or call) and redirect stdout/stderr somewhere. They're currently hooked to your own process's stdout and stderr, which is why they're coming through.
If you need something that can integrate nicely with your GUI event loop, use Twisted's process-launching stuff.
Related
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Running a process in pythonw with Popen without a console
How do I eliminate Windows consoles from spawned processes in Python (2.7)?
I have a Python program that calls a separate number-crunching program (written in C) as a subprocess several times (using subprocess.check_call). It works great on Linux, and it works great on Windows too except for one little thing: every time it calls the subprocess a Command Prompt window is created and then soon destroyed when the subprocess exits.
This doesn't affect the computation at all, but it's very annoying because this window keeps flashing on and off the screen, and it makes it difficult to do other things on the computer because the new Command Prompt window can steal keyboard focus.
How can I simply execute the subprocess (which has no GUI), and prevent the Command Prompt window from being created?
How are you calling subprocess.check_call()? If you pass shell=True then the window should not be created as this will cause the SW_HIDE flag to be set for the STARTUPINFO.wShowWindow attribute.
Example:
subprocess.check_call(["ping", "google.com"], shell=True)
When you build the C application, set its type to the Win32 Subsystem instead of the Console Subsystem. If this is a pre-built application, you could change the subsystem with this tool.
I want to write a Python script which will start a GUI program (as in, run a binary program with subprocess.run or os.system or something). The script should not block until the program is done, it should start it and then keep running.
I'm doing this on Ubuntu.
I tried subprocess.Popen, but if I run, say subprocess.Popen("gedit"), I get strange behavior. If I open the Ubuntu system monitor (process manager), I can see that the gedit process appears when I run the script, and the gedit window itself opens. But if I close the window, the process doesn't end in the system monitor. The process stays there until my python script exits.
How can I get the behavior I want? The only thing I can think of right now is to just call subprocess.run in a different Python thread, is that the only thing I can do?
Try using subprocess.call. This has worked for me before.
subprocess.call(['command', 'arguments'])
The program should end when the window is closed.
You have to kill the subprocess you've created before you exit the program.
Try this.
I am trying to set up daemontools with a large python program that spawns various subprocesses, and I'm having issues where the subprocesses are not spawning correctly. The subprocess just appears as a zombified process when launched via daemontools.
I have provided a simplified example to demonstrate this.
/service/test/run:
#!/bin/sh
cd /script_directory/
exec envdir /service/test/env /usr/bin/python3 test_subprocess.py
/script_directory/test_subprocess.py
import subprocess
from time import sleep
subprocess.Popen("xterm")
while True:
sleep(1)
test_subprocess.py simply launches a GUI terminal and stays alive, so I can see if it is still running in top/htop.
If I run the script either as root or a non-root user, the script properly executes and the window is displayed. When run via daemontools/supervise, the xterm is zombified and no window is shown.
Setting the env/DISPLAY and env/XAUTHORITY variables as described here doesn't seem to work for me.
On further investigation, the subprocess is zombified even if it does not use the GUI. For example if the subprocess in subprocess.py is "top" - it will not run.
I've used daemontools successfully on various other projects that don't spawn subprocesses so I don't think the issue is with the basic setup here.
Can daemontools be used with scripts that spawn other processes?
If not, what some other recommended tools for daemonising complex python applications?
bro i can't understand what you went to do. but try this program:
import subprocess
p = subprocess.Popen(
['xterm', '-hold'], stdin=subprocess.PIPE)
p.communicate()
if went to give some argument use -e and type command,and if another problem please let me know.thanks
I am working on a python script to analyze astronomy images and I am trying to open a DS9 window within a python script (DS9 is a utility that allows images to be interactively viewed and analyzed). Usually I would open DS9 by going into the Linux terminal and typing:
>ds9 &
and then it would pop up in another window.
I tried to mimic this in my python script by writing the following line:
os.system('ds9 &')
When I would run the script the DS9 window would pop up but the rest of the script would not run until I closed the DS9 window. This gave me errors because the tasks that followed needed a DS9 window to be opened.
I am wondering if there is a way to open a window from within a python scripts and still have the rest of the script continue running.
Perhaps:
os.system('ds9 &')
isn't the right approach?
You can use subprocess module.
subprocess is a newer way to spawn processes rather than using os.spawn*() or os.system().
In your case:
import subprocess
subprocess.Popen(["ds9"])
This should run ds9 in background.
See the documentation here.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Running a process in pythonw with Popen without a console
How do I eliminate Windows consoles from spawned processes in Python (2.7)?
I have a Python program that calls a separate number-crunching program (written in C) as a subprocess several times (using subprocess.check_call). It works great on Linux, and it works great on Windows too except for one little thing: every time it calls the subprocess a Command Prompt window is created and then soon destroyed when the subprocess exits.
This doesn't affect the computation at all, but it's very annoying because this window keeps flashing on and off the screen, and it makes it difficult to do other things on the computer because the new Command Prompt window can steal keyboard focus.
How can I simply execute the subprocess (which has no GUI), and prevent the Command Prompt window from being created?
How are you calling subprocess.check_call()? If you pass shell=True then the window should not be created as this will cause the SW_HIDE flag to be set for the STARTUPINFO.wShowWindow attribute.
Example:
subprocess.check_call(["ping", "google.com"], shell=True)
When you build the C application, set its type to the Win32 Subsystem instead of the Console Subsystem. If this is a pre-built application, you could change the subsystem with this tool.