tags:

views:

74

answers:

3

I am confused by the first 2 params, module and command-line. I find unless I populate both it doesn't work right, and it seems the documentation says otherwise.

I want to call "testApp.exe param1=123"

The only way I found that works is:

CreateProcess("testApp.exe","testApp.exe param1=123",...

I thought either of these should work, but no luck so far:

CreateProcess("testApp.exe","param1=123",...
CreateProcess(NULL,"testApp.exe param1=123",...

I've read the msdn docs a few times so what am I missing?

+1  A: 

The first parameter is the name of the executable to run. The second parameter is the command line. The command-line need not contain the name of the executable, if it doesn't however and you pass something like

"param1 param2"

then in your program, argv[0] == "param1" and argv[1] == "param2". Therefore, you usually have to pass the name of the executable as the first value to satisfy the program's requirements, not Windows'.

If you do not pass the executable name, it is extracted from the first value in the command line string.

avakar
The process being called is a C# app, with `static int Main(string[] args)` where the executable name is _not_ included. Is that the issue?
John
@John, the command-line is always passed to the process as a single string (exactly the string that you pass as a second parameter to `CreateProcess`), it is up to the process' runtime to parse it. Whether C# ignores the first token in that string is irrelevant.
avakar
A: 

Instead of giving name of executable try to give full path with name of executable.

user001
+1  A: 

I discuss issues with getting CreateProcess to run exes in an article here. There are multiple things that can go wrong, including the requirement for fully qualified paths, and absent exe names in the command line.

Bob Moore