How to execute a command in cmd using CreateProcess?
<p>I'm trying to launch the command line through my c++ program and then have cmd run a command. I'm not sure what I'm doing wrong. I've looked at the MSDN documentation but I'm unable to understand what to change in my code.</p>

<p>Below is the chunk of code that I have written. I'm trying to launch cmd and then run the command in cmdArgs. However, on running the program it just launches the cmd without running the nslookup part of it. I've tried with other commands as well like ipconfig, but they do not get executed. Could someone help me understand what I'm doing wrong.</p>

<p>When I launch the program, it just opens up cmd. What I'm trying to do is have the cmdArgs runs and view the output on the cmd screen.</p>

<p>I'm new to c++, so if this is trivial I apologize. I've looked at other questions on the site, but it seems that the format of cmdArgs is correct - program name followed by the arg.</p>

<pre><code>STARTUPINFO si; 
PROCESS_INFORMATION pi;

ZeroMemory(&amp;si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&amp;pi, sizeof(pi));

LPTSTR cmdPath = _T("C:\\Windows\\System32\\cmd.exe");
LPTSTR cmdArgs = _T("C:\\Windows\\System32\\cmd.exe nslookup myip.opendns.com. resolver1.opendns.com");


if (!CreateProcess(cmdPath, cmdArgs, NULL, NULL, FALSE, 0, NULL, NULL, &amp;si, &amp;pi))
{
    std::cout &lt;&lt; "Create Process failed: " &lt;&lt; GetLastError() &lt;&lt; std::endl;
    return "Failed";
}
</code></pre>