0

这就是我所拥有的:

@ECHO OFF

IF [%1]==[](
  SET /P server=What url would you like to proxy to? :
  SET /P location=What is the path to your local files? :
)

IF [%1]==[ggp](
  SET server=10.10.10.10
  SET location=c:/Users/Brook/Desktop/hello
)


start chrome.exe localhost:8080/login

call:startServer

:startServer

  node httpdp.js --server %server% --srcpath %location%

  %ifErr% (
    call:startServer
  )

GOTO:EOF

当 if 条件被取出时,文件运行良好,所以我的语法有问题,但我不知道。

在检查参数是否与各种字符串匹配之后,我实际上想将第一个 if 条件放在 else 或 default 块中,如果有人知道该怎么做......

谢谢!

4

2 回答 2

1

这改进了一些语法,使其更加健壮,并停止子例程被调用两次。未知命令也已修复。

@ECHO OFF

IF "%~1"=="" (
  SET /P server=What url would you like to proxy to? :
  SET /P location=What is the path to your local files? :
)

IF /i "%~1"=="ggp" (
  SET server=10.10.10.10
  SET location=c:\Users\Brook\Desktop\hello
)


start "" chrome.exe localhost:8080/login

call:startServer
goto :EOF

:startServer

  node httpdp.js --server %server% --srcpath %location%

REM unknown command  %ifErr% (  call:startServer )

GOTO:EOF
于 2013-09-14T03:25:43.010 回答
0

这行得通,但它可能会得到改进。

@ECHO OFF

IF [%1]==[ggp] GOTO ggp

GOTO default

:ggp

SET server=10.10.10.10
SET location=c:/Users/Brook/Desktop/hello
GOTO always

:default

SET /P server=What url would you like to proxy to? :
SET /P location=What is the path to your local files? :
GOTO always

:always

start chrome.exe localhost:8080/login

call:startServer

:startServer

  node httpdp.js --server %server% --srcpath %location%

  %ifErr% (
    call:startServer
  )

GOTO:EOF
于 2013-09-13T15:37:13.113 回答