Difference in running C++ program in command prompt and PowerShell Difference in running C++ program in command prompt and PowerShell powershell powershell

Difference in running C++ program in command prompt and PowerShell


The main difference:

  • cmd.exe provides true binary (byte-stream) conduits, so that >, the redirection operator, can capture an external program's raw byte output.

  • PowerShell, as of version 7.2, only ever uses text (strings) to communicate with external programs, both on in- and output, which means that external-program output is invariably decoded to .NET strings, which has the following implications:

    • Even when only using PowerShell's > operator to send an external program's output to a file, each line output by an external program is first decoded into a .NET string and then, on saving to the target file, encoded again, in this case using the Out-File cmdlet's default encoding, which the > operator is an effective alias of.

      • In Windows PowerShell, that (cmdlet-specific) encoding is UTF-16LE ("Unicode"), whereas in PowerShell (Core) 6+, it is BOM-less UTF-8, the encoding used consistently in that PowerShell edition.
    • This decoding-reencoding cycle not only slows things down, but also means:

      • For text output, the input character encoding (as decoded from the external program) may be different from the output-by-PowerShell character encoding.

      • Binary in- and output is fundamentally unsupported.

        • The simplest workaround is to delegate to cmd.exe with cmd /c ... (on Windows) and to /bin/sh with sh -c ... (on Unix-like platforms.
    • See this answer for more information.


The program itself is just a process, it doesn't really matter how you launch it.

The notable difference is that, while both consoles connect themselves to the standard input and output streams of the process, everyone has its own performance while renderizing it, so the IO calls may be more or less impacted by this.

Technically, a console is just a program that invokes your program and graphically shows your output (and other things).