“Remote command failed with exit status 127”

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
kansal.nishant
Posts: 1
Joined: 03 Sep 2016 21:10

“Remote command failed with exit status 127”

#1 Post by kansal.nishant » 03 Sep 2016 21:25

I have a batch file as below:



Set-up: I have Jenkins installed on windows and via sshexec task in ANT, I am calling the above batch file in a remote windows machine using cygwin openssh.

Issue: The above script when called from Jenkins job using above set-up, it is returning “Remote command failed with exit status 127”. However, if I am hard coding the value of %var% in cd as cd c:\X\Y\Z\a.b.c rather than passing as cd c:\X\Y\Z\%var%, script is executing fine, i.e.; directly changing the directory with the exact path (cd C:\X.Y.Z.\1.2.3).

I tried couple of ways to handle path setting and call uninstaller.exe after changing the directory but no success.

Please help.

modedit: code placed in code tags and moved below the text.

Code: Select all

@echo off

REM <--Fetching installed service pack version and storing it in var-->
FOR /f "tokens=* " %%a in ('findstr /I "install.servicepack" ^< "C:\A\B\C\D.properties" ') DO SET temp=%%a
SET var=%temp:~22%
REM <-- I tested, correct value is getting assigned to var say 1.2.3-->

REM <--Next, I am changing the directory using CD, in which X, Y and Z is a fixed directory path and after that it is variable based upon %var% value

cd c:\X\Y\Z\%var%
echo %cd%
REM <-- I tested and directory is correctly set against cd c:\X\Y\Z\1.2.3

REM <--With in c:\X\Y\Z\%var% (c:\X\Y\Z\1.2.3), there is an exe called uninstaller.exe and I am executing it is below:
dir
ECHO MESSAGE: Starting Silent Uninstallation of ABC Package
uninstaller.exe -options -silent
ECHO MESSAGE: Finished Silent Uninstallation of ABC Package

douglas.swehla
Posts: 75
Joined: 01 Jun 2016 09:25

Re: “Remote command failed with exit status 127”

#2 Post by douglas.swehla » 13 Sep 2016 17:41

kansal.nishant wrote:. . .it is returning “Remote command failed with exit status 127”. However, if I am hard coding the value of %var% in cd as cd c:\X\Y\Z\a.b.c rather than passing as cd c:\X\Y\Z\%var%, script is executing fine

I tried couple of ways to handle path setting and call uninstaller.exe after changing the directory but no success.


It's not clear which command is returning the error code. Is it uninstall.exe, or openssh? This SO post says that SH returns error 127 when it can't find the command in the search path. Maybe that utility doesn't start its search in the current directory, and can't find UNINSTALL, even though it's right there.

Some other possible reasons why what you've posted doesn't work:
  • You have unquoted spaces in the file path. What does %var% (%svcpak_dir%, in my examples) expand to?
  • The code you've shown is nested inside a FOR loop. If so, you'll need to use delayed expansion.
  • The problem is with cygwin. I don't know how well openssh plays with Windows. The native tools for remote system management are WINRM and WINRS.

Here are some quick things to try:

Code: Select all

:: Make sure you quote file paths.

for /f "tokens=* " %%a in ('findstr /I "install.servicepack" ^< "C:\A\B\C\D.properties" ') do set "svcpak=%%a"
set "svcpak_dir=%svcpak:~22%"

cd "C:\X\Y\Z\%svcpak_dir%"
uninstaller.exe -options -silent


Code: Select all

:: Use PUSHD/POPD instead of CD

for /f "tokens=* " %%a in ('findstr /I "install.servicepack" ^< "C:\A\B\C\D.properties" ') do set "svcpak=%%a"
set "svcpak_dir=%svcpak:~22%"

pushd "C:\X\Y\Z\%svcpak_dir%"
uninstaller.exe -options -silent
popd


Code: Select all

:: Run the UNINSTALL command directly, without changing directories.

for /f "tokens=* " %%a in ('findstr /I "install.servicepack" ^< "C:\A\B\C\D.properties" ') do set "svcpak=%%a"
set "svcpak_dir=%svcpak:~22%"

"C:\X\Y\Z\%svcpak_dir%\uninstaller.exe" -options -silent


Code: Select all

:: Rely on CMD.EXE's search path, rather than whatever cygwin is using.

for /f "tokens=* " %%a in ('findstr /I "install.servicepack" ^< "C:\A\B\C\D.properties" ') do set "svcpak=%%a"
set "svcpak_dir=%svcpak:~22%"

cmd /c ""C:\X\Y\Z\%svcpak_dir%\uninstaller.exe" -options -silent"


For best results, post the whole script you are working on, along with a copy of the actual output. Hiding usernames is fine, but seeing actual output lets us see and respond to things that you might not have recognized as important.

Also, tell us the things you've tried already, so we don't suggest those again.

Post Reply