Closed mrclary closed 11 months ago
ping @jaimergp
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!
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?
Yea, exactly, that's the part I was mentioning:
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.
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
This could work (see last comment on that answer).
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? 🤷🏼♂️
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'
I also get the same behavior bypassing PowerShell
This is strange because cmd start
should hide any terminal windows when running.
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!
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\"",
]
Perhaps an infinite series of nested shells would converge to zero visibility 🤣
cep-devel
has the snippet above now, which should make things snappier!
Two pieces of information to add to the mix:
But one side effect is that the application launched inside the bat file does not have focus if another application is already open.
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.
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.
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).
Checklist
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 themenu.json
file to specify whether the shortcut should suppress this behavior andmenuinst
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