The error mentioned in the original post ("...NativeCommandError") appears when re-directing stderr to stdout, either e.g. by "...>file 2>&1", or by "*>file". As mentioned above, PowerShell produces this error if something is output via stderr, even if that 'something' is just normal logs (no errors). "CMake" e.g. uses stderr as normal trace output stream. While old Windows Command shell/script does NOT interpret any content on stderr as evidence of an error, PowerShell does, if the executable (e.g. CMake) is invoked with "Invoke-Expression", or called directly.
But!... if the executable is invoked with "Start-Process", this same problem does NOT occur.
Concretely, case 1:
Invoke-Expression cmake .... 1>$logFile1 2>$logFile2
OR
Invoke-Expression cmake .... *>$logFile
This leads to the above error
Case 2:
Start-Process cmake -ArgumentList $arguments ... -RedirectStandardOutput $logFile1 -RedirectStandardError $logFile2
The error doesn't appear. The files are 'clean', but two output files are populated
Conclusion: PowerShell behaves differently depending on how the executable is invoked
Powershell should preferably behave like the (old) Windows command shell, given the executables that are out there and that need to be run without experiencing such problems. The exit codes should hopefully suffice for qualifying errors. If this is really not possible, this feature of PowerShell - interpreting anything via stderr as error - should be switchable. Last but not least, the inconsistent behavior in that respect, and among the different means of invoking an executable, would best be avoided.
If you don't like streaming into two separate files as proposed in the case of 'Start-Process', the solution that works is to invoke the executable in the old command shell context, by use of "cmd /c" in the PowerShell script. Then you get both stdout and stderr streamed into ONE SINGLE file, AND properly populated (that is interleaved) by both streams as the executable operates. Example:
cmd /c "cmake ... >$logFile 2>&1"