1. How To Use wxShell or wxExecute Without Opening A Console Window
- Posted by euphoric (admin) Apr 06, 2023
- 618 views
I'm trying to call another app from within my wxEuphoria app, and wxExecute and wxShell always generate a console window.
Anybody know a way to prevent that console window from popping up?
2. Re: How To Use wxShell or wxExecute Without Opening A Console Window
- Posted by katsmeow Apr 06, 2023
- 589 views
According to the manual:
system_exec() does not start a new command shell.
Kat
3. Re: How To Use wxShell or wxExecute Without Opening A Console Window
- Posted by euphoric (admin) Apr 06, 2023
- 593 views
According to the manual:
system_exec() does not start a new command shell.
Kat
Unfortunately, it seems to be doing so in my case.
I'm using the 'start' command in Windows. That might be the culprit.
I'll confirm and try different iterations of all functions and calls tomorrow...
4. Re: How To Use wxShell or wxExecute Without Opening A Console Window
- Posted by ghaberek (admin) Apr 07, 2023
- 643 views
I'm using the 'start' command in Windows. That might be the culprit.
I assume you're using something like cmd.exe /C start <filename> to start the default application for a file and you're running your app with euiw.exe.
Running cmd.exe requires a console window, and since euiw.exe doesn't have one already, a new one gets created. The solution there is to not run cmd.exe to "start" a file.
...but wxExecute uses CreateProcess which only is for starting executables and you need to use ShellExecute which can launch a file into its default app.
...but wxEuphoria "classic" is based on wxWidgets 2.8 which does not have any such function. Starting with 2.9 they added wxLaunchDefaultApplication and that does use ShellExecute.
So I guess we need to write our own wxLaunchDefaultApplication which, peeking at the wxWidgets source code for Windows and Linux, is pretty simple. This version is further simplified.
include wxeu/wxeud.e ifdef LINUX then include std/filesys.e constant XDG_OPEN = locate_file("xdg-open",getenv("PATH")) elsifdef WINDOWS then include std/dll.e include std/machine.e constant SW_SHOWDEFAULT = 10, shell32 = open_dll("shell32.dll"), xShellExecute = define_c_func(shell32,"ShellExecuteA",{C_HANDLE, C_POINTER,C_POINTER,C_POINTER,C_POINTER,C_INT},C_HANDLE) end ifdef public function wxLaunchDefaultApplication( sequence document ) ifdef LINUX then if wx_execute(XDG_OPEN & ' ' & document) then return wxTrue end if elsifdef WINDOWS then atom lpFile = allocate_string(document,1) integer nShowCmd = SW_SHOWDEFAULT if c_func(xShellExecute,{0,0,lpFile,0,0,nShowCmd}) > 32 then return wxTrue end if end ifdef return wxFalse end function
-Greg
5. Re: How To Use wxShell or wxExecute Without Opening A Console Window
- Posted by euphoric (admin) Apr 07, 2023
- 605 views
Thank you, @ghaberek. My issue has been resolved.
I'm using the 'start' command in Windows. That might be the culprit.
I assume you're using something like cmd.exe /C start <filename> to start the default application for a file and you're running your app with euiw.exe.
I didn't have cmd.exe in my prompt.
sequence cmd = "start /min winword /q /z\"" & template & "\"" wx_execute(cmd) --system_exec(cmd) --wx_shell( cmd )
In context, it was doing a test for the Windows version, then calling some function based on that. It seems, however, that it was constantly defaulting to using wx_shell(), which I think was the root of the problem.
So, it seems that was a bug in my code, and that using a commandline of "start" without cmd.exe shouldn't have even worked, so it was always calling wx_shell(), which I'm guessing opens a commandline console and runs the given prompt.
So I guess we need to write our own wxLaunchDefaultApplication...
...which works perfectly for Windows 11. I'm just going to cross my fingers that it works across all prior versions of Windows. (Yes, there will be tests later.)
Thank you, @ghaberek! I owe you coffee AND lunch.
6. Re: How To Use wxShell or wxExecute Without Opening A Console Window
- Posted by ghaberek (admin) Apr 07, 2023
- 581 views
So, it seems that was a bug in my code, and that using a commandline of "start" without cmd.exe shouldn't have even worked, so it was always calling wx_shell(), which I'm guessing opens a commandline console and runs the given prompt.
Yes, "start" command works in wx_shell() because it's telling cmd.exe to run the command, and cmd.exe supports the "start" command.
My assumption above was the same thing, just by launching cmd.exe with wx_execute() and using the /C flag to run the same "start" command.
...which works perfectly for Windows 11. I'm just going to cross my fingers that it works across all prior versions of Windows. (Yes, there will be tests later.)
It ought to. According to the documentation for ShellExecute it's been supported since XP, though I suspect it goes back even further.
Thank you, @ghaberek! I owe you coffee AND lunch.
One day I will hold you to that, sir.
-Greg