【问题标题】:“Remote command failed with exit status 127”“远程命令失败,退出状态为 127”
【发布时间】:2016-09-03 21:22:27
【问题描述】:

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

@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\a.b.c 而不是作为 cd c:\X\Y\Z\%var% 传递,则脚本执行正常, IE。;直接更改具有确切路径的目录(cd C:\X.Y.Z.\1.2.3)。

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

请帮忙。

【问题讨论】:

    标签: windows batch-file jenkins ant


    【解决方案1】:

    不要更改TEMP 变量的值:这是一个保存临时目录环境的特殊系统变量。变量。

    请选择另一个变量名。

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

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

    【讨论】:

    • 感谢Jean 的提示...会记住的。
    • 用“Setlocal enabledelayedexpansion”和“cd C:\X\Y\Z\!var!\”修改脚本...结果还是一样:执行:[sshexec]连接到系统: 22 [sshexec] cmd : /home/superuser/callbatch.sh c:/Deploy/test.bat [sshexec] 消息:开始静默卸载 ABC 包 [sshexec] C:\X\Y\Z\1.2.3 [sshexec ] ************************************************* ****************************** [sshexec] 消息:完成卸载 ABC 包构建失败 D:\BuildFile\NK-WINCMP-2.xml :8: 远程命令失败,退出状态为 127
    • 查看我的编辑。我对变量扩展错了。真正的问题一定是 TEMP。
    • 准确地说...问题在于使用 temp...我将其更改为另一个用户定义的变量,它工作得很好。非常感谢让。
    • 好。一个恶毒的!如果可行,请接受答案。
    猜你喜欢
    • 2013-03-30
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多