Skip to content

Support for building .exe files that are both GUI and CLI apps (--windowed --console) #6244

@maltfield

Description

@maltfield

Is your feature request related to a problem? Please describe.

I have a python app that supports both GUI and CLI execution, but the PyInstaller builds of my app can only be built with --noconsole or --console

If I use --console, then there's always this annoying command prompt console window that opens at the same time as a user double-clicks the .exe (in GUI mode)

If I use --noconsole, then the second (command prompt) window doesn't open, but it breaks the .exe when called on the command line (in CLI mode) because the command prompt now doesn't show any output from the app.

I'm not alone. There's a lot of people who have experienced this issue when building their apps with PyInstaller:

Describe the solution you'd like

Support to open an app without the console (--noconsole) at run time if the app is executed in the GUI. And also support console output at run time if the app is executed from within the CLI.

Describe alternatives you've considered

Making users execute | more at the end of their command-line executions. It's a pretty awful work-around.

Additional context

My example app:

I'm not sure how others implement this, but for my app:

  1. If there's no command-line arguments, then the GUI window opens
  2. If there's command-line arguments, then it works in CLI mode (no GUI window opens; output to the user happens on the command line)

Example Execution

For my app, I expect that most of my users will be using the app in GUI mode, so I've enabled --noconsole (set console=False in the buskill.spec file

But with this set, CLI execution gives no output. For example:

C:\Users\user\Downloads\buskill-win-1632568907-x86_64\buskill-win-1632568907-x86_64\buskill-1632568907-x86_64>buskill.exe --help
 
C:\Users\user\Downloads\buskill-win-1632568907-x86_64\buskill-win-1632568907-x86_64\buskill-1632568907-x86_64>

However, per the StackOverflow link above, we can force the output to be visible by appending | more

C:\Users\user\Downloads\buskill-win-1632568907-x86_64\buskill-win-1632568907-x86_64\buskill-1632568907-x86_64>buskill.exe --help | more
buskill version {'VERSION': '1632568907', 'GITHUB_REF': 'refs/heads/dev', 'GITHUB_SHA': '29102dc99feaf2359d3aa1d76460e8068c45af15', 'SOURCE_DATE_EPOCH': '1632568907'}
usage: buskill [-h] [--version] [-v] [-a] [-U]
 
App for arming and configuring BusKill. For help, see https://docs.buskill.in
 
optional arguments:
  -h, --help     show this help message and exit
  --version      print version and exit.
  -v, --verbose  increase output verbosity
  -a, --arm      Arms BusKill
  -U, --upgrade  Download & upgrade latest version of BusKill
 
 
C:\Users\user\Downloads\buskill-win-1632568907-x86_64\buskill-win-1632568907-x86_64\buskill-1632568907-x86_64>

I have no idea why this | more hack works, and I wonder if it's possible to fix this in PyInstaller so ti's not necessary.

The prerelease buskill app v1632568907 from above can be downloaded from here for testing:

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions