2

I have an SAP program call sapgenpse.exe.

If i excute the below command from powershell command, the output is perfect.

enter image description here

But if i do the same operation in powershell ISE, the output breaks abruptly. enter image description here

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
aravind M
  • 21
  • 3

1 Answers1

2

It looks like sapgenpse.exe outputs to the stderr stream rather than to stdout.

Unfortunately, the Windows PowerShell ISE - unlike the regular console - treats and renders stderr output from external programs as errors, even though that isn't appropriate, given that stderr output cannot be assumed to (always) represent errors.
(I have no explanation for the strange format you're getting, however).

There are two workarounds:

  • Redirect PowerShell's error stream (through which stderr output is routed in the ISE) to its success output stream, and call the .ToString() method on each error record:
.\sapgenpse.exe ... 2>&1 | ForEach-Object ToString
  • Call your executable via cmd.exe and use its redirection features to redirect stderr to stdout:
cmd /c '.\sapgenpse.exe ... 2>&1'

As an aside:

mklement0
  • 382,024
  • 64
  • 607
  • 775