regarding spawnProcess and parameters in Windows

Hugo Florentino hugo at acdam.cu
Mon Dec 16 01:33:53 PST 2013


On Mon, 16 Dec 2013 02:04:10 +0100, Danny Arends wrote:
> ...
> So I think this should work:
>
> spawnProcess([appexe,format("/INI=%s",appini)],
> ["",""],Config.suppressConsole);
>

Hmm... that did not work either, it complained that the parameter was 
not correct. Actually, the syntax I was using should have worked 
(according to documentation, second overload of spawnProcess), and I 
also (unsuccessfully) tried with function execute.

Anyway, since my launcher will only be run from Windows, finally I 
decided to call ShellExecuteA directly (I find it less cumbersome to use 
and actually more elegant).

However, something is bothering me: when running the launcher, it opens 
a console temporarily before launching the other process (even when I am 
not using std.stdio) and I cannot get rid of this behavior.

This is the code I am now using:

import std.file: exists, getcwd;
import std.path: buildPath, dirName;
import std.string: format, toStringz;
import core.sys.windows.windows;

immutable static auto appname = "myapp";

extern(Windows) HANDLE ShellExecuteA(HWND, LPCSTR, LPCSTR, LPCSTR, 
LPCSTR, int);

int main(string[] args) {
   auto appath = getcwd();
   auto appexe = buildPath(appath, appname ~ ".exe");
   if (exists(appexe)) {
     auto param = format(`/ini="%s"`, buildPath(appath, appname ~ 
".ini"));
     ShellExecuteA(null, "", toStringz(appexe), toStringz(param), "", 
SW_SHOWMAXIMIZED);
     scope(failure) return -1;
   }
   return 0;
}

Why does the console window appear and how can I prevent this?

Regards, Hugo


More information about the Digitalmars-d-learn mailing list