--noconsole on Windows and subprocess call

2,200 views
Skip to first unread message

Bryan A. Jones

unread,
Jan 10, 2014, 4:00:39 PM1/10/14
to pyins...@googlegroups.com, Andrei Kopats
All,

I'm stuck with a Pyinstaller problem (Windows 7, latest pyinstaller from git, Python 2.7). I'd like to create an application without a console window, so I pass --noconsole to pyinstaller. However, I also call some external programs from my application, which is causing problems:
  1. If I use subprocess.call and friends, I get the exception OSError exception "[Error 6] the handle is invalid." This is because a noconsole app has no stdin/stdout/stderr; by default, subprocess tries to pass these on to the child process, which fails.
  2. If I use subprocess.call with stdin=PIPE, stdout=PIPE, stderr=PIPE (which opens a pipe between the child process and my parent Python process), everything works, but I get a command window that appears briefly on the screen. Because I call this child process a lot, I see a lot of distracting consoles opening and closing.
  3. Trying op.spawnl produces identical results to #2.
All the code works fine when running without --noconsole or running directly from Python. Any ideas on how to run a child subprocess successfully, but without opening a console window?

Thanks!

Bryan
--
Bryan A. Jones, Ph.D.
Associate Professor
Department of Electrical and Computer Engineering
231 Simrall / PO Box 9571
Mississippi State University
Mississippi state, MS 39762
http://www.ece.msstate.edu/~bjones
bjones AT ece DOT msstate DOT edu
voice 662-325-3149
fax 662-325-2298

Our Master, Jesus Christ, is on his way. He'll show up right on
time, his arrival guaranteed by the Blessed and Undisputed Ruler,
High King, High God.
- 1 Tim. 6:14b-15 (The Message)

Martin Zibricky

unread,
Jan 11, 2014, 5:21:37 PM1/11/14
to pyins...@googlegroups.com
On Friday 10 of January 2014 15:00:39 Bryan A. Jones wrote:
> All the code works fine when running without --noconsole or running
> directly from Python. Any ideas on how to run a child subprocess
> successfully, but without opening a console window?

Do you have any code that would reproduce this behavior easily?
signature.asc

Bryan A. Jones

unread,
Jan 14, 2014, 11:33:21 AM1/14/14
to pyins...@googlegroups.com
Yes. Running the attached subprocess_test.py produces out.txt containing 'Failed: [Error 6] The handle is invalid' when run as pyinstaller --noconsole subprocess_test.py. Running using pyinstaller subprocess_test.py or python subprocess_test.py produces the usual Python help text.

Bryan
subprocess_test.py

Michael Hipp

unread,
Jan 11, 2014, 2:47:19 PM1/11/14
to pyins...@googlegroups.com
Have you tried calling it something like this:
Popen(cmd, creationflags=win32process.CREATE_NO_WINDOW)


--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To post to this group, send email to pyins...@googlegroups.com.
Visit this group at http://groups.google.com/group/pyinstaller.
For more options, visit https://groups.google.com/groups/opt_out.

Bryan A. Jones

unread,
Jan 24, 2014, 5:32:47 PM1/24/14
to pyins...@googlegroups.com
All,

Another programmer helped me find a nice approach that still uses the newer subprocess module. Is there a good place to post this on the Pyinstaller site? I hope that it can help others who stumble across the same problem. This works directly from Python, and from the pyinstaller binary, and from the pyinstaller binary when using --noconsole.

import subprocess
with open('out.txt', 'w') as f:
    try:
        si = subprocess.STARTUPINFO()
        si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
        h = subprocess.check_output(['python', '--help'],
            stdin=subprocess.PIPE,
            stderr=subprocess.PIPE,
            startupinfo=si)
        f.write(h)
    except OSError as e:
        f.write('Failed: ' + str(e))

Michael Hipp

unread,
Jan 24, 2014, 8:19:22 PM1/24/14
to pyins...@googlegroups.com
I'd imagine this might be the correct place: http://www.pyinstaller.org/wiki/Recipe

Bryan A. Jones

unread,
Jan 27, 2014, 10:36:10 AM1/27/14
to pyins...@googlegroups.com
OK, I'm dumb. I can't find any edit button or link on the Trac wiki page given above, even after registering to create an account. Any pointers?

Steve Barnes

unread,
Jan 27, 2014, 1:32:51 PM1/27/14
to pyins...@googlegroups.com
On 27/01/14 15:36, Bryan A. Jones wrote:
OK, I'm dumb. I can't find any edit button or link on the Trac wiki page given above, even after registering to create an account. Any pointers?


To create a new recipe, please put a WikiPageName at the end of the URL of this page (after the Recipe/).

Any help!

Bryan A. Jones

unread,
Jan 27, 2014, 3:45:02 PM1/27/14
to pyins...@googlegroups.com
Steve,

Thanks! I tried that, but got a "Page Recipe/Subprocess not found" error for the URL of http://www.pyinstaller.org/wiki/Recipe/Subprocess while I was logged in. I can't follow the instructions at http://www.pyinstaller.org/wiki/WikiNewPage, which tell me to edit an existing page to add a link to a new page, since I can't find an edit button / link.

Bryan


--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To post to this group, send email to pyins...@googlegroups.com.
Visit this group at http://groups.google.com/group/pyinstaller.
For more options, visit https://groups.google.com/groups/opt_out.

Steve Barnes

unread,
Jan 27, 2014, 4:13:51 PM1/27/14
to pyins...@googlegroups.com
On 27/01/14 20:45, Bryan A. Jones wrote:
Steve,

Thanks! I tried that, but got a "Page Recipe/Subprocess not found" error for the URL of http://www.pyinstaller.org/wiki/Recipe/Subprocess while I was logged in. I can't follow the instructions at http://www.pyinstaller.org/wiki/WikiNewPage, which tell me to edit an existing page to add a link to a new page, since I can't find an edit button / link.

Bryan

Bryan,

There is a bit here, http://universaleditbutton.org/Universal_Edit_Button, about an edit button that should appear when you are on an editable page.

Not set up an account to try it but it looks hopeful.

Steve

Bryan A. Jones

unread,
Jan 27, 2014, 5:26:38 PM1/27/14
to pyins...@googlegroups.com
Steve,

Thanks. I installed it, but it doesn't appear when I'm on the trac wiki.

Bryan


--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To post to this group, send email to pyins...@googlegroups.com.
Visit this group at http://groups.google.com/group/pyinstaller.
For more options, visit https://groups.google.com/groups/opt_out.

Steve Barnes

unread,
Jan 28, 2014, 1:17:01 AM1/28/14
to pyins...@googlegroups.com
On 27/01/14 22:26, Bryan A. Jones wrote:
> Steve,
>
> Thanks. I installed it, but it doesn't appear when I'm on the trac wiki.
>
> Bryan
>
Sorry Bryan I'm out of ideas!

tomas....@gmail.com

unread,
Jan 31, 2014, 8:51:29 AM1/31/14
to pyins...@googlegroups.com
Hi,

I'm facing similar kind of problems although a bit different.

In my case, the subprocess opens a new window on its own and the
pyinstaller -noconsole option does not seem to apply to that window.
In addition to the new window that I want, I get an additional empty
terminal window. The solution as suggested by Bryan does not work
since I actually want the window to stay open, but I don't want the
console.

Any ideas on how to handle that case so that the -noconsole also
applies to any windows opened by subprocesses?

Windows 7
Python 2.6.2
PyInstaller 2.1


Thankful for any help.
BR,
Tomas Melin
Reply all
Reply to author
Forward
0 new messages