【问题标题】:strange issue with labels标签的奇怪问题
【发布时间】:2017-01-10 13:03:20
【问题描述】:

我有一个脚本:

IF "%USER_COUNTRY%"=="ie" IF NOT "%POS_TYPE%" == "ipos" ( GOTO IE_Start)

下面我有一些标签:

:PT_Start
ECHO Start PT
  rem for PT Num Lock must be activated before POS start
  .\native\klocks.exe +n

    IF NOT EXIST c:\C3 GOTO NO_C3
    pushd c:\C3\
    tskill /V  /A  c3_net
    cmd /c  START /min c3_net.exe
    GOTO C3_DONE
    :NO_C3
    ECHO C3 not present in C:\C3\
    ECHO start without C3
    :C3_DONE
    popd

GOTO Start_Now

:IE_Start
ECHO Start IE

    IF NOT EXIST c:\C3 GOTO NO_C3_RPM
    pushd c:\C3\
    tskill /V  /A  c3_rpm_net
    cmd /c START  c3_rpm_net.exe
    GOTO RPM_C3_DONE
    :NO_C3_RPM
    ECHO C3 not present in C:\C3\
    ECHO start without C3
    :RPM_C3_DONE
    popd

GOTO Start_Now

:PL_Start
ECHO Start PL
    pushd c:\AModule\
    cmd /c START Forcom.AModule.exe
    echo "AModule ist gestartet"
    popd

GOTO Start_Now

我得到:

The system cannot find the batch label specified - IE_Start

脚本在 Windows 下运行,但它保存在 Unix 上,因此它具有 LF 行结束符。我这么说是因为解决这个问题的方法很少,但我不明白为什么。我注意到以下解决了问题:

  1. 将换行符更改为 CR+LF(特定于 Windows);
  2. IE_Start标签及其部分代码移到PT_Start之前;
  3. cmd /c START /min c3_net.exe 中删除/min
  4. 将第 3 点的行改成cmd /c START /min C:\C3\c3_net.exe(反正这个文件不存在);

发生了什么事?

【问题讨论】:

  • 这是不是 bash
  • 不管其他问题如何,您代码中的:IE_Start 永远不会从您发布的代码块中运行,我们知道它可以从您脚本中其他地方的GOTO 运行。 IF /I "%USER_COUNTRY%"=="ie" (IF /I NOT "%POS_TYPE%"=="ipos" GOTO IE_Start) 。但是您确实需要包含所有代码。

标签: windows batch-file label line-endings


【解决方案1】:
IF "%USER_COUNTRY%"=="ie" IF NOT "%POS_TYPE%" == "ipos" ( GOTO IE_Start)

您上面的代码不正确:

1) 您使用两个不同的 if 语句作为一个衬里。

2) 第一个 if 包含条件但缺少命令块。

下面是实现你想要的正确方法。

IF "%USER_COUNTRY%"=="ie" ( do something )

IF NOT "%POS_TYPE%"=="ipos" ( GOTO IE_Start)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 1970-01-01
    • 2012-05-13
    • 2011-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多