7

Im trying to start a wxPython app that (I have converted to an exe with py2exe) from a process that is running in the background.

The problem is that when the gui app opens, so does a console window (c:\windows\system\cmd.exe)

I had a look at this question where Alex Martelli suggests setting the creationflags paramater of Popen to 0x08000000 but this hasn't solved my problem.

Also I wonder if there is a better way of running a process in the background, at the moment I just changed the extension of the script to pyw and since it doesn't have a GUI then it isn't visible...

This is line that calls the subprocess

    subprocess.Popen(args="%s"%comPort,bufsize=0,
                     executable="myFrozen_WxpythonApp.exe",
                     creationflags=0x08000000, shell=False)

py2exe script

...

options = {'py2exe': {'compressed': 3,
                          'optimize': 2,
                          'excludes': excludes,
                          'packages': packages,
                          'dll_excludes': dll_excludes,
                          'bundle_files': 1,
                          'dist_dir': 'dist',
                          'xref': False,
                          'skip_archive': False,
                          'ascii': False,
                          #'packages': packages,
                        'custom_boot_script': '',
                         }
                }  

      setup(options=options, windows=["app.pyw"], zipfile=None, data_files=data_files)

Update:

As I explained in my answer to this question the problem was in the subprocess.Popen call.

The first string in the args parameter should be the name of the executable, the executable name can then be followed by any commands or data that needs to be passed to the subprocess.

13
  • Please put a newline or two in your code block. Commented Dec 4, 2010 at 23:18
  • That's unrelated to subprocess and the console window of the main script. It's WxpythonApp's console window popping up (and it should still pop up when you started it alone). Commented Dec 4, 2010 at 23:21
  • @delnan: I wish it were that simple. The windows parameter was set when converting to an exe with py2exe and the console window does not open if I manually execute the app, i.e. double click it.. Commented Dec 4, 2010 at 23:24
  • Ya... as much as it is annoying! Commented Dec 4, 2010 at 23:35
  • Could you show us the relevant parts of the py2exe script? Commented Dec 5, 2010 at 0:04

1 Answer 1

3

I figured out what I was doing wrong after reading the documentation for subprocess.Popen

The first string in the args parameter should be the name of the executable. I didn't include the name of the executable as I thought that was taken care of with the executable paramater.

Sign up to request clarification or add additional context in comments.

3 Comments

Ah, very good. Sounds like you've answered your own question. I suggest you update your question with the solution you found. BTW, the docs are most definitely misleading regarding the args parameter when they say it "... can be explicitly set by using the executable argument" which seems to imply it can be left out of the args.
So what can the executable para do? when i set the executable name in **args para**, and the executable path in executable para. It didn't work.
@Samuel: I think the way it works is that Popen() will use the first argument in args as the program to execute unless you also provide the optional executable argument in which case that value will override it. In either case the contents of entire args parameter is passed to program that actually gets run as its command-line whether or not the first argument of it is what was used to start it or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.