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:


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 C:\Jenkins\workspace\MyBuildMachine> C:\Users\NO\Desktop\MyApp.exe 
08:13:56 Unhandled Exception: System.IO.IOException: The handle is invalid.
08:13:56    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
08:13:56    at System.Console.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
08:13:56    at MyApp.App.AppInit(String[] args)
08:13:56    at MyApp.Program.Main(String[] args)
08:13:56 C:\Jenkins\workspace\MyBuildMachine>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: [email protected]
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:\> MyApp.exe >> 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).

  • Does the command run on the jenkins box as well when you ssh to it?
    – 030
    Commented Nov 29, 2017 at 16:32

1 Answer 1


I found out how to do it without pipeline. It only has to do with command line script:

start "" C:\MyApp\MyApp.exe >> 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 >> text.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.