Tutorial :system and CreateProcess()


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.


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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »