Jenkins Exception that is caused by stdout redirection using windows cmd I'm trying to execute an exec file from a jenkins server, using windows cmd. This is what is run from jenkins Windows batch window:

C:\MyApp\MyApp.exe

When run regularly from command line, the app prints to the console reporting its progress.

When I run it from jenkins, I get the following exception (MyApp stands for the name of my actual application):

08:13:56 Started by user NO
08:13:56 Building remotely on SFM BSP builder (ComputerName) (projectName) in workspace C:\Jenkins\workspace\MyBuildMachine
08:13:56 Running Prebuild steps
08:13:56 [MyBuildMachine] $ cmd /c call C:\Windows\TEMP\jenkins3066529473565168228.bat
08:13:56 
08:13:56 C:\Jenkins\workspace\MyBuildMachine&gt; C:\Users\NO\Desktop\MyApp.exe 
08:13:56 
08:13:56 Unhandled Exception: System.IO.IOException: The handle is invalid.
08:13:56 
08:13:56    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
08:13:56    at System.Console.GetBufferInfo(Boolean throwOnNoConsole, Boolean&amp; succeeded)
08:13:56    at MyApp.App.AppInit(String[] args)
08:13:56    at MyApp.Program.Main(String[] args)
08:13:56 
08:13:56 C:\Jenkins\workspace\MyBuildMachine&gt;exit 255 
08:13:56 Build step 'Execute Windows batch command' marked build as failure
08:13:56 Email was triggered for: Failure - Any
08:13:56 Sending email for trigger: Failure - Any
08:13:56 Sending email to: myEmail@email.com
08:13:58 Finished: FAILURE


Needless to say, the app didn't do its job.
Trying to understand the problem, I found here an explanation about stdout redirection, and Jenkins actually does that automatically, which causes this exception. And indeed also when I run it in cmd with stdout redirection, i.e. C:\&gt; MyApp.exe &gt;&gt; appOut.txt, it shows the same error.

I have no access to the source code of the app. I know that it could be solved from inside. My question is: Is there any way to prevent Jenkins from redirecting the stdout to a file, or wrapping the exec somehow such that will allow me to run it? (of course, running it from another exec and just catching the exception won't work. There won't be an exception but also the app won't run).
I found out how to do it without pipeline. It only has to do with command line script:

start "" C:\MyApp\MyApp.exe &gt;&gt; text.txt


This call is asynchronous (i.e., the command line won't wait for MyApp.exe to return). If you want it to wait, you can use the /w flag, like this:

start /w "" C:\MyApp\MyApp.exe &gt;&gt; text.txt