Jenkins is unable to run exe batch commands

I am calling a batch file “Generate.bat” through Pipeline in Jenkins. it perfectly works if Generate.bat have some script which does not interfere with some other .exe. But my Generate.bat is calling an hexview.exe file with passing some argument and here Jenkin does not work. It stuck at the line where it is calling hexview.exe with some argument. Generate.bat works perfectly if I manually double click it but does not work with Jenkin. sharing you one dummy code of batch file:
set HEXVIEW_EXE=“HexViewPath\hexview.exe”
%HEXVIEW_EXE% argument1 argument2…argumentN

Can somebody help me how I can resolve this issue?

Hello and welcome to this community, @Nikhil_Tambi. :wave:

Your issue might be related to the environment in which Jenkins runs the batch file. Jenkins runs batch files in a non-interactive shell, which can sometimes cause issues with certain executables.

Here are a few steps that might help troubleshoot and, who knows, resolve the issue:

  1. Make sure that the path to hexview.exe is correct and accessible by Jenkins. You can use an absolute path to avoid any path-related issues.
  2. Ensure that Jenkins has the necessary permissions to run hexview.exe. You might need to run Jenkins as an administrator.
  3. Add logging to your batch file to capture any error messages or output from hexview.exe.
  4. Use the start command to run hexview.exe in a new window. This can sometimes help with executables that require a GUI or specific environment.

Here is an updated version of your Generate.bat file with logging and the start command:

@echo off
set HEXVIEW_EXE="HexViewPath\hexview.exe"
echo Running %HEXVIEW_EXE% with arguments %*
start "" %HEXVIEW_EXE% %*
if %errorlevel% neq 0 (
    echo Error: %HEXVIEW_EXE% failed with error code %errorlevel%
    exit /b %errorlevel%
)
echo %HEXVIEW_EXE% completed successfully

@echo off: Turns off command echoing.
echo Running %HEXVIEW_EXE% with arguments %*: Logs the command being run.
start "" %HEXVIEW_EXE% %*: Runs hexview.exe in a new window.
if %errorlevel% neq 0: Checks if hexview.exe returned an error code and logs it.
echo %HEXVIEW_EXE% completed successfully: Logs successful completion.

Make sure your Jenkins Pipeline is correctly calling the batch file.
Here is an untested example of how to call the batch file in a Jenkins Pipeline:

pipeline {
    agent any
    stages {
        stage('Run Generate.bat') {
            steps {
                bat 'Generate.bat argument1 argument2 argumentN'
            }
        }
    }
}

I tried all the option which you have shared but it is not working.

1 Like