Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow suppressing cmd.exe windows on launching applications #128

Closed
2 tasks done
mrclary opened this issue Apr 18, 2023 · 16 comments
Closed
2 tasks done

Allow suppressing cmd.exe windows on launching applications #128

mrclary opened this issue Apr 18, 2023 · 16 comments
Labels
locked [bot] locked due to inactivity type::feature request for a new feature or capability

Comments

@mrclary
Copy link

mrclary commented Apr 18, 2023

Checklist

  • I added a descriptive title
  • I searched open requests and couldn't find a duplicate

What is the idea?

When launching applications from shortcuts created by menuinst on Windows, a cmd.exe window opens. A key should be provided in the menu.json file to specify whether the shortcut should suppress this behavior and menuinst should take the necessary steps to enforce this when creating the shortcut.

Why is this needed?

Unwanted cmd.exe windows are not suppressed.

What should happen?

cmd.exe windows should be suppressed or not according to specification in the menu.json file.

Additional Context

No response

@mrclary mrclary added the type::feature request for a new feature or capability label Apr 18, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New in 🧭 Planning Apr 18, 2023
@mrclary
Copy link
Author

mrclary commented Apr 18, 2023

ping @jaimergp

@jaimergp
Copy link
Contributor

We have some logic for this, but it might be not working. Take a look at the windows module in the cep-devel branch. I am typing from the phone, sorry for the brevity!

@mrclary
Copy link
Author

mrclary commented Apr 18, 2023

Hmm... I don't see anything in cep-devel. But upon closer review, the cmd.exe window is only visible for a brief flash, then disappears; also the shorcut "Target" is:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "start 'C:\Users\rclary\AppData\Local\Spyder-5.4.4.dev1521\envs\spyder-5.4.4.dev1521\Menu\Spyder.bat' -WindowStyle hidden"

which has -WindowStyle hidden. Perhaps this is related to #127?

@jaimergp
Copy link
Contributor

Yea, exactly, that's the part I was mentioning:

command = [
str(system32 / "WindowsPowerShell" / "v1.0" / "powershell.exe"),
f"\"start '{script}' -WindowStyle hidden\"",
]

Maybe the activation scripts are launching CMD on their own too, perhaps an oversight. Let's leave this open because I need to investigate further.

@jaimergp
Copy link
Contributor

We might need a different approach (VBScript?) since the flashing behaviour is a known issue:

https://superuser.com/questions/62525/run-a-batch-file-in-a-completely-hidden-way

@ccordoba12
Copy link

This could work (see last comment on that answer).

@mrclary
Copy link
Author

mrclary commented Apr 19, 2023

This could work (see last comment on that answer).

I added /MIN to the shortcut target, but it did not seem to have any affect

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "start /MIN 'C:\Users\rclary\AppData\Local\Spyder-5.4.4.dev1521\envs\spyder-5.4.4.dev1521\Menu\Spyder.bat' -WindowStyle hidden"

Commenting out the entire contents of Spyder.bat did not have any affect either (except that Spyder does not start, as expected), the cmd window still flashes with titlebar "Spyder". So I don't think it has anything to do with the @CALL %ACTIVATOR% in Spyder.bat.

Something about -WindowStyle hidden in the shortcut target is not being respected. I'm wondering if this may be related to #127: if the icons are consolidated, perhaps the hidden window directive will be respected? 🤷🏼‍♂️

@mrclary
Copy link
Author

mrclary commented Apr 19, 2023

I also get the same behavior bypassing PowerShell

C:\WINDOWS\system32\cmd.exe /c start /min 'C:\Users\rclary\AppData\Local\Spyder-5.4.4.dev1521\envs\spyder-5.4.4.dev1521\Menu\Spyder.bat'

@ccordoba12
Copy link

I also get the same behavior bypassing PowerShell

This is strange because cmd start should hide any terminal windows when running.

@jaimergp
Copy link
Contributor

I am looking into this as part of #119 and one thing I noticed is that Powershell does indeed hide the CMD window. What we see is the powershell dialog starting CMD 😬

I checked with the bare cmd /C START... and it doesn't work as expected. It also leaves the dialog open 🤷

It's getting more and more complicated with so many shell layers calling each other!

@jaimergp
Copy link
Contributor

Uh, turns out this way of launching the script produces an almost invisible flash 😂

command = [
    f'"{system32 / "cmd.exe"}"', "/C", "START", "/MIN", '""',
    f'"{system32 / "WindowsPowerShell" / "v1.0" / "powershell.exe"}"',
    "-WindowStyle", "hidden",
    f"\"start '{script}' {arg1}-WindowStyle hidden\"",
]

@mrclary
Copy link
Author

mrclary commented May 22, 2023

Perhaps an infinite series of nested shells would converge to zero visibility 🤣

@jaimergp
Copy link
Contributor

cep-devel has the snippet above now, which should make things snappier!

@mrclary
Copy link
Author

mrclary commented Jun 22, 2023

Two pieces of information to add to the mix:

  1. If I set the "Run:" shortcut property to "Minimized", then I don't see the cmd window flash.
    Screenshot 2023-06-22 at 11 21 51 AM
    But one side effect is that the application launched inside the bat file does not have focus if another application is already open.
  2. If I don't request environment activation and don't have a precommand, then the Spyder.bat script is not created and the command is used as the shortcut target instead of Spyder.bat. In this case, with command as {{ PREFIX }}\pythonw.exe {{ PREFIX }}\Scripts\spyder-script.py, there is no cmd window flash. spyder-script.py is created at conda install and is determined by Spyder's feedstock.
    The drawback is that environment activation and precommand aren't used. In the case of Spyder, we may not need these, but as a general solution this could be a problem.

A note: spyder.exe is created by conda install as well but will always generate a cmd window if used, under any circumstance.

@jaimergp
Copy link
Contributor

The CMD flash is a byproduct of us having to run some shell code before running the shortcut target, sadly. If the shortcut doesn't need activation or pre-launch logic, then we can call it directly. If it works for Spyder, then perfect! Less moving parts too.

Activation is default in case some package in the dependency tree requires activation-time logic to work properly (e.g. let's say compilers) and it can be difficult for users to diagnose.

@jaimergp
Copy link
Contributor

Current approach doesn't "flash" but still creates a (short lived) console window that is minimized to task bar. Still hacky and not ideal but It Works (tm).

@github-project-automation github-project-automation bot moved this from 🆕 New to 🏁 Done in 🧭 Planning Jul 24, 2023
@github-actions github-actions bot added the locked [bot] locked due to inactivity label Jul 24, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked [bot] locked due to inactivity type::feature request for a new feature or capability
Projects
Archived in project
Development

No branches or pull requests

3 participants