debugMinor
Jenkins Exception that is caused by stdout redirection using windows cmd
Viewed 0 times
stdoutexceptionjenkinsredirectionthatusingwindowscmdcaused
Problem
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):
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.
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, runn
C:\MyApp\MyApp.exeWhen 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> 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& 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>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: FAILURENeedless 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, runn
Solution
I found out how to do it without pipeline. It only has to do with command line script:
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 "" C:\MyApp\MyApp.exe >> text.txtThis 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.txtCode Snippets
start "" C:\MyApp\MyApp.exe >> text.txtstart /w "" C:\MyApp\MyApp.exe >> text.txtContext
StackExchange DevOps Q#2728, answer score: 2
Revisions (0)
No revisions yet.