为什么我的简单批处理脚本在第59行后意外退出?

时间:2016-01-01 17:02:22

标签: windows batch-file

我制作了这个批处理文件来执行我的web开发工具包的某些命令,但是,bat文件在第59行之后退出。为什么要退出?

但是,我注意到,如果我从文件中删除第59行并运行它。它工作正常。唯一的问题是,我必须在bat文件完成后物理输入该行。

您可以尝试通过从我的GitHub下载kit并将zip的内容解压缩到您喜欢的位置来重现该问题。

只需导航到Gulp/Starter Kit目录并运行setup.bat文件即可。

批处理文件:

@echo off
TITLE Starter Kit
runas /noprofile /user:Administrator cmd
goto :checkNodeVersion

:checkNodeVersion
  cls
  echo Current NodeJS version:
  call npm -v
  timeout 5
  if errorlevel 1 goto :installNode
  goto :updateNode

:installNode
  cls
  echo Installing NodeJS:
  powershell -Command "(New-Object Net.WebClient).DownloadFile('https://nodejs.org/dist/v5.3.0/node-v5.3.0-x64.msi', 'node-v5.3.0-x64.msi')"
  echo downloading file, node-v5.3.0-x64.msi, from https://nodejs.org/dist/v5.3.0/node-v5.3.0-x64.msi....
  set "fileName=node-v5.3.0-x64.msi"
  %fileName%

  echo NodeJS was successfully installed.
  timeout 5
  goto :updateNode

:updateNode
  cls
  echo Updating NodeJS:
  call npm cache clean -f
  call npm install -g n
  call n stable

  cls
  echo NodeJS was successfully updated to version #:
  node -v
  timeout 5
  goto :installBower

:installBower
  cls
  echo Installing Bower:
  call npm install -g gulp bower

  echo Bower was successfully installed.
  goto :installGulp

:installGulp
  cls
  echo Installing GulpJS:
  call npm install -g gulp

  echo GulpJS was successfully installed.
  timeout 5
  goto :installDependencies

:installDependencies
  cls
  echo Installing Project Dependencies:
  call npm install && bower install
  ::Quits unexpectedly after line 59
  call npm install --save-dev gulp-rucksack
  call npm install --save-dev gulp-imagemin
  call npm install --save imagemin-pngquant

  echo Project Dependencies were successfully installed.
  timeout 5
  goto :primaryFunction

:primaryFunction
  cls
  echo Starter Kit Log:
  echo NodeJS is installed.
  echo GulpJS is installed.
  echo Gulp Dependencies are installed.
  set /p response="Would you like to continue? <y/n>"

  if /i "%response%"=="y" (
    cls
    set "filePath=%~dp0"
    cd %filePath%

    gulp help
    cmd /k
  )

  if /i "%response%"=="n" goto :exitFunction

:exitFunction
  cls
  echo Starter Kit is Closing
  exit

1 个答案:

答案 0 :(得分:1)

根据https://www.jetbrains.com/webstorm/help/bower.html的以下引用,bower是一个批处理脚本(.cmd文件)。

  

在此字段中,指定Bower可执行文件的位置   ( bower.cmd 或其他,具体取决于所使用的操作系统。)

所以你需要改变第59行,如下所示:

  call npm install && call bower install

如果没有CALL,你永远不会从凉亭返回。

相关问题