www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - SpawnProcess fails when console is hidden

reply "Nemo" <fake nowhere.com> writes:

I have win32 program, which takes command line parameters and 
passes them trough socket to another program, running on the same 
machine. If connection fails, it needs to start the another 

I don't want console to popup so I added "-L/SUBSYSTEM:WINDOWS". 
This works fine, except when it would need to start the another 
program, which fails silently. And I guess because console is 
hidden, no error messages or exceptions appear if I try to run it 
from console. Removing the linker directive makes spawnProcess 
work. To make this mysterious, when I run it from eclipse DDT it 
works all the time...

The starting happens in catch:
} catch (SocketException ex) {
    spawnProcess([`c:\Progra~1\XXX\YYY\program.exe`, recipe]);

I am all out of ideas, so all help is appreciated.
Sep 08 2013
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
My guess, just looking at it, is that spawnProcess fails because 
there's  no streams available for stdin, stdout, and stderr. It 
tries to reuse the ones of the parent process, but without a 
console they don't work.

It might help to use Config.suppressConsole.. I'm just guessing 
but maybe try:

spawnProcess(`[c:\.......]`, recipe, Config.suppressConsole);

and see what happens. Alternatively maybe redirect the stdin, 
stdout, and stderr to log files instead of using the default (by 
passing File arguments to spawnProcess too)
Sep 08 2013
parent "Nemo" <notinuse nowhere.com> writes:
Thank you, Config.suppressConsole did not help, but redirecting 
the std:s did.
Sep 08 2013