2016-03-07 187 views
1

我有一個批處理文件,將檢查CPU架構(32或64位),並相應地執行命令。它會找到特定的文件夾並執行某些.exe文件。我的問題是,如果我在if語句中有一個聲明,例如。 '回顯一些文本',它會顯示正常,這意味着對體系結構的檢查很好。但只要在我的If語句中有多個命令,批處理文件立即退出。我的代碼到目前爲止:命令不執行.BAT如果語句

@echo off 

SET "ARCH=x64" 
IF NOT EXIST "%SystemRoot%\SysWOW64\cmd.exe" ( 
IF NOT DEFINED PROCESSOR_ARCHITEW6432 SET "ARCH=x86" 
) 
IF "%ARCH%"=="x64" (
    cd \ 
    cd Program Files (x86)\MySQL\MySQL Installer for Windows 
    start /wait MySQLInstallerConsole community install server;5.6.26;x64:*:type=config;openfirewall=true;generallog=true;binlog=true;serverid=3306;enable_tcpip=true;port=3306;rootpasswd=somepass -silent 

    cd \ 
    cd Program Files (x86)\Location 
    start /wait DatabaseConfig 
) ELSE (
    cd \ 
    cd Program Files\MySQL\MySQL Installer for Windows 
    start /wait MySQLInstallerConsole community install server;5.6.26;x86:*:type=config;openfirewall=true;generallog=true;binlog=true;serverid=3306;enable_tcpip=true;port=3306;rootpasswd=somepass -silent 

    cd \ 
    cd Program Files\Location 
    start /wait DatabaseConfig 
) 

pause 

如果我有從下面自己的if語句外運行的命令,它工作正常。

​​

回答

2

這是因爲在Program Files (x86) path.Closing支架的支架被作爲IF command.Try的一部分,這(路徑用雙引號):

@echo off 

SET "ARCH=x64" 
IF NOT EXIST "%SystemRoot%\SysWOW64\cmd.exe" ( 
IF NOT DEFINED PROCESSOR_ARCHITEW6432 SET "ARCH=x86" 
) 
IF "%ARCH%"=="x64" (
    cd \ 

    cd "Program Files (x86)\MySQL\MySQL Installer for Windows" 
    start /wait MySQLInstallerConsole community install server;5.6.26;x64:*:type=config;openfirewall=true;generallog=true;binlog=true;serverid=3306;enable_tcpip=true;port=3306;rootpasswd=somepass -silent 

    cd \ 
    cd "Program Files (x86)\Location" 
    start /wait DatabaseConfig 
) ELSE (
    cd \ 
    cd "Program Files\MySQL\MySQL Installer for Windows" 
    start /wait MySQLInstallerConsole community install server;5.6.26;x86:*:type=config;openfirewall=true;generallog=true;binlog=true;serverid=3306;enable_tcpip=true;port=3306;rootpasswd=somepass -silent 

    cd \ 
    cd "Program Files\Location" 
    start /wait DatabaseConfig 
) 

pause 
+0

這奏效了!謝謝! – nerdalert