“远程命令失败,退出状态为127”

时间:2016-09-03 21:22:28

标签: windows batch-file jenkins ant

我有一个批处理文件如下:

@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

设置:我在Windows上安装了Jenkins并通过ANT中的sshexec任务,我使用cygwin openssh在远程Windows机器上调用上述批处理文件。

问题:使用上述设置从Jenkins作业调用上述脚本时,它返回“远程命令失败并退出状态127”。但是,如果我将cd中的%var%的值硬编码为cd c:\ X \ Y \ Z \ abc而不是传递为cd c:\ X \ Y \ Z \%var%,则脚本执行正常,即;使用确切的路径直接更改目录(cd C:\ X.Y.Z. \ 1.2.3)。

我尝试了几种方法在更改目录后调用uninstaller.exe但没有成功。

请帮忙。

1 个答案:

答案 0 :(得分:0)

不要更改TEMP变量的值:这是一个包含临时目录env的特殊系统变量。变量

请选择其他变量名称。

FOR /f "tokens=* " %%a in ('findstr /I "install.servicepack" ^< "C:\A\B\C\D.properties" ') DO SET t=%%a
SET var=%t:~22%

如果更改临时目录,依赖它的程序可能会崩溃(并且有很多程序)。