regarding spawnProcess and parameters in Windows

Danny Arends Danny.Arends at gmail.com
Sun Dec 15 17:04:10 PST 2013


On Monday, 16 December 2013 at 00:59:51 UTC, Danny Arends wrote:
> On Sunday, 15 December 2013 at 23:14:45 UTC, Hugo Florentino 
> wrote:
>> Hello,
>>
>> I am trying to do a small launcher for a Windows application 
>> which (in order to be portable) requires a specific parameter, 
>> and I am getting this error when I try to run it in Windows 7 
>> SP1:
>>
>> "std.process.ProcessException at std\process.d(518): Failed to 
>> spawn new process (Access denied.)"
>>
>> This is the code I am trying to use:
>>
>> import std.stdio, std.file, std.path, std.string, std.process;
>>
>> static auto appname = "myapp";
>>
>> int main(string[] args) {
>>  auto appath = dirName(thisExePath());
>>  auto appexe = buildPath(appath, appname ~ ".exe");
>>  auto appini = buildPath(appath, appname ~ ".ini");
>>  auto applaunchpars = format(`"%s" /ini="%s"`, appexe, appini);
>>  if (exists(appexe)) {
>>    auto appPid = spawnProcess(applaunchpars, ["" : ""], 
>> Config.suppressConsole);
>>    scope(failure) return -1;
>>  }
>>  return 0;
>> }
>>
>> The ugly ["" : ""] hack is because I haven't been able to 
>> invoke spawnProcess otherwise, at least withouth specifying 
>> stdin and stdout (which I don't really need right now). 
>> Actually, I was thinking in making my own wrapper for 
>> ShellExecuteA (I don't find spawnProcess particularly 
>> intuitive), but I would prefer "the D way".
>>
>> Anyway, Where could the problem be?
>>
>> Regards, Hugo
>
> You need to pass the INI parameters separately see:
>
> http://dlang.org/phobos/std_process.html#.spawnProcess
>
> spawnProcess([appexe,format("/INI=%s")], ["",""], 
> Config.suppressConsole);
>
> Gr,
> Danny Arends
> http://www.dannyarends.nl

Pressed send too fast:

1) Separately = As an array

2) And I also forgot the appini variable

So I think this should work:

spawnProcess([appexe,format("/INI=%s",appini)], 
["",""],Config.suppressConsole);

Gr,
Danny Arends
http://www.dannyarends.nl


More information about the Digitalmars-d-learn mailing list