0

I have made a GUI for my application. All scripts are in Python (2.7) and the GUI is created with Tkinter. I work on Linux, but I needed this app to be executable on Windows. So I've used py2exe, to create an executable. After a while it is working almost perfectly, but I have the following problem:

Somewhere in the application, I need to call external programs, namely ImageMagick and LaTeX. I use the commands convert, pdflatex, simply by importing os module and running os.system(build), where build = 'convert page.pdf page.gif'etc. When those commands are called from the *.exe application the console pops up (meaning a console window opens up for a split of a second and closes again). Is there a way, to prevent this behaviour?

It does not interrupt the application, but it is ugly and not a desired behaviour.

[Note] I chose not to add any samples, since there are lots of files and other content, which, I think, is not related to the problem. I could however try to post minimal (not)working example. But maybe it is not needed.

Thanks!

quapka
  • 2,799
  • 4
  • 21
  • 35
  • try using subprocess module with a \c modifier – Busturdust Oct 26 '15 at 18:05
  • There also may be some software specific "silent" commands. For instance `build = 'convert page.pdf page.gif` may have an equivalent `convert page.pdg page.gif silent` option – Busturdust Oct 26 '15 at 18:19
  • or -quiet http://www.imagemagick.org/script/command-line-options.php – Busturdust Oct 26 '15 at 18:21
  • Possible duplicate of [How do I hide the console when I use os.system() or subprocess.call()?](http://stackoverflow.com/questions/7006238/how-do-i-hide-the-console-when-i-use-os-system-or-subprocess-call) – Eryk Sun Oct 26 '15 at 19:20

1 Answers1

0

import subprocess subprocess.Popen("application.exe", shell = True)

Busturdust
  • 2,447
  • 24
  • 41
  • If you're using a trusted command and require the shell, then setting `shell=True` is a simple way to configure `startupinfo` to hide the console window. This runs the command using `%ComSpec% /c` (e.g. `%SystemRoot%\System32\cmd.exe /c`), just like `os.system`. However, I prefer to use `shell=False` and set the `creationflags` parameter to `DETACHED_PROCESS` (8). With this option no console window is created for an executable that's flagged as a console application (e.g. cmd.exe, powershell.exe, python.exe), because the child process doesn't start an instance of the console host, conhost.exe. – Eryk Sun Oct 26 '15 at 22:00