title: When outputting commands from cmd.exe (CreatProcess) I get "More?" Why and how to get rid of it?
body: <p>I have a problem with the second output from cmd.exe.
  I use: CreatePipe () to link processes; CreateProcess () to create a process that runs 'cmd.exe'.</p>
  <p>The problem is that I cannot get the correct output from cmd.exe</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  
  using namespace std;
  
  
  #define deffBuffSize 4096
  
  
  int funCo() {
  
      HANDLE writeToCL, readFromCL, writeToProcess, readFromProcess;
      char lpCmdLine[] = &quot;cmd.exe&quot;, lpCL[512];
      memset(lpCL, '\0', 512);
      if (GetEnvironmentVariableA(&quot;COMSPEC&quot;, lpCL, 512) == 0) {
          cout &lt;&lt; &quot;GetEnvironmentVariableA error :: &quot; &lt;&lt; GetLastError() &lt;&lt; endl;
      }
      cout &lt;&lt; lpCL &lt;&lt; endl;
      STARTUPINFOA siA;
      PROCESS_INFORMATION piApp;
      SECURITY_ATTRIBUTES secAttr;
      ZeroMemory(&amp;secAttr, sizeof(SECURITY_ATTRIBUTES));
      ZeroMemory(&amp;siA, sizeof(STARTUPINFOA));
      secAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
      secAttr.lpSecurityDescriptor = NULL;
      secAttr.bInheritHandle = TRUE;
  
      if (CreatePipe(&amp;readFromCL, &amp;writeToProcess, &amp;secAttr, 0) == 0) {
          cout &lt;&lt; &quot;Create pipe error :: &quot; &lt;&lt; GetLastError() &lt;&lt; endl;
          return 1;
      }
      if (!SetHandleInformation(readFromCL, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) {
          cout &lt;&lt; &quot;SetHandleInformation error :: &quot; &lt;&lt; GetLastError() &lt;&lt; endl;
      }
  
      if (CreatePipe(&amp;readFromProcess, &amp;writeToCL, &amp;secAttr, 0) == 0) {
          cout &lt;&lt; &quot;Create pipe error :: &quot; &lt;&lt; GetLastError() &lt;&lt; endl;
          return 1;
      }
      if (!SetHandleInformation(writeToCL, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) {
          cout &lt;&lt; &quot;SetHandleInformation error :: &quot; &lt;&lt; GetLastError() &lt;&lt; endl;
      }
  
      siA.cb = sizeof(STARTUPINFOA);
      siA.hStdInput = readFromProcess;
      siA.hStdOutput = writeToProcess;
      siA.hStdError = writeToProcess;
      siA.dwFlags = STARTF_USESTDHANDLES;
  
  
      if (CreateProcessA(lpCL, NULL, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &amp;siA, &amp;piApp) == 0) {
          cout &lt;&lt; &quot;CreateProcessA error :: &quot; &lt;&lt; GetLastError() &lt;&lt; endl;
          return 1;
      }
      
      CloseHandle(readFromProcess);
      CloseHandle(writeToProcess);
  
      Sleep(2000);
      DWORD dRead = 0, dWrite = 0;
      char chBuff[deffBuffSize];
      memset(chBuff, '\0', deffBuffSize);
      if (ReadFile(readFromCL, chBuff, deffBuffSize, &amp;dRead, NULL) == FALSE) {
          cout &lt;&lt; &quot;ReadFile error :: &quot; &lt;&lt; GetLastError() &lt;&lt; endl;
          return 1;
      }
      cout &lt;&lt; chBuff;
  
      for (;;) {
          memset(chBuff, '\0', deffBuffSize);
          fgets(chBuff, deffBuffSize, stdin);
          if (WriteFile(writeToCL, chBuff, sizeof(chBuff), &amp;dWrite, NULL) == FALSE) {
              cout &lt;&lt; &quot;WriteFile error :: &quot; &lt;&lt; GetLastError() &lt;&lt; endl;
              return 1;
          }
          Sleep(2000);
          memset(chBuff, '\0', deffBuffSize);
          if (ReadFile(readFromCL, chBuff, deffBuffSize, &amp;dRead, NULL) == FALSE) {
              cout &lt;&lt; &quot;ReadFile error :: &quot; &lt;&lt; GetLastError() &lt;&lt; endl;
              return 1;
          }
          cout &lt;&lt; chBuff;
  
      }
  
      CloseHandle(writeToCL);
      CloseHandle(readFromCL);
      CloseHandle(piApp.hProcess);
      CloseHandle(piApp.hThread);
      return 0;
  }
  
  int main() {
      int result = 0;
      result = funCo();
      cout &lt;&lt; endl;
      system(&quot;pause&quot;);
      return result;
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/O0XtP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O0XtP.png" alt="Console output of parent process" /></a></p>
  <ul>
  <li>The yellow marker is the command entered by the user.</li>
  <li>Red marker - output of the command result.</li>
  </ul>
  <p><strong>If the output is &quot;More?&quot; press ENTER, then we will receive an error that ERROR_BROKEN_PIPE (109) - The pipe has been ended.</strong></p>
  <p><a href="https://i.stack.imgur.com/rHTNK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rHTNK.png" alt="Error screenshot" /></a></p>
  <p>How do I understand &quot;More?&quot; writes if you want to display the next sheet of information.</p>
  <p>But how to get around this &quot;More?&quot;</p>
  <p>Help please, I will be very grateful to you. =)</p>
  <p><strong>The part below relates to comments:</strong></p>
  <p><strong>Autoscroll not disabled</strong></p>
  <p><a href="https://i.stack.imgur.com/JzMU4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JzMU4.png" alt="cmd -&gt; Properties" /></a></p>
  <p><strong>I tried using a static command when writing to cmd.exe</strong></p>
  <p>But after this action I find myself in a &quot;deadlock&quot;</p>
  <pre><code>Sleep(2000);
      DWORD dRead = 0, dWrite = 0;
      char chBuff[deffBuffSize];
      memset(chBuff, '\0', deffBuffSize);
      if (ReadFile(readFromCL, chBuff, deffBuffSize, &amp;dRead, NULL) == FALSE) {
          cout &lt;&lt; &quot;ReadFile error :: &quot; &lt;&lt; GetLastError() &lt;&lt; endl;
          return 1;
      }
      cout &lt;&lt; chBuff;
      char outMes[] = &quot;ipconfig\0&quot;;
  
      for (;;) {
          /*memset(chBuff, '\0', deffBuffSize);
          fgets(chBuff, deffBuffSize, stdin);*/
          
          if (WriteFile(writeToCL, outMes, sizeof(outMes), &amp;dWrite, NULL) == FALSE) {
              cout &lt;&lt; &quot;WriteFile error :: &quot; &lt;&lt; GetLastError() &lt;&lt; endl;
              return 1;
          }
          cout &lt;&lt; &quot;WriteFile :: &quot; &lt;&lt; dWrite &lt;&lt; endl;
          Sleep(2000);
          memset(chBuff, '\0', deffBuffSize);
          if (ReadFile(readFromCL, chBuff, deffBuffSize, &amp;dRead, NULL) == FALSE) {
              cout &lt;&lt; &quot;ReadFile error :: &quot; &lt;&lt; GetLastError() &lt;&lt; endl;
              return 1;
          }
          cout &lt;&lt; chBuff;
  
      }
  </code></pre>