tags:

views:

46

answers:

1

I have a command,I need to execute the same using C Program. I have stored the entire command ,with arguments, in the variable cmdline. When I am using system(cmdline),it is working fine. But on using the following: ret = CreateProcess(NULL, cmdline, (LPSECURITY_ATTRIBUTES)NULL, (LPSECURITY_ATTRIBUTES)NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &startup, &pinfo);

I am getting the return code as 2 in GetLastError().

Can somebody tell the reason? Thanks in advance.

+1  A: 

Maybe the program name contains whitespace?

From MSDN: If lpApplicationName is NULL, the first white-space – delimited token of the command line specifies the module name. If you are using a long file name that contains a space, use quoted strings to indicate where the file name ends and the arguments begin.

Alex Farber
+1 If the OP is getting file-not-found, this is the most likely explanation.
Bob Moore