2014-11-04 54 views
0

我有一個基於用戶輸入運行FluentMigrator遷移的批處理文件。最後一步是運行如下的遷移:在批處理文件中獲取Migrate.exe的輸出

"%~dp0\FluentMigrator.1.1.2.1\tools\Migrate.exe" /conn "DATA SOURCE=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=%HostName%)(PORT=%ServerPort%))(CONNECT_DATA=(SERVICE_NAME=%ServiceName%)));PASSWORD=%installerUserPW%;PERSIST SECURITY INFO=True;USER ID=%installerUserName%;" /provider oracle /context %installerUserName% /assembly ./bin/Debug/DatabaseMigrations.dll >> install_log.txt 

ECHO. 
echo ------------------------------------------------------------------------------->> install_log.txt 
echo ------------------ Database Setup has executed successfully ------------------ >> install_log.txt 
echo ------------------------------------------------------------------------------->> install_log.txt 
TYPE install_log.txt 
GOTO:EOF 

一樣需要這工作 - 該Migrate.exe應用程序的所有打印輸出到文件,然後成功的消息,然後將文件寫入到控制檯所以有一個控制檯和文件副本。但是,如果遷移失敗,例如,如果用戶不具有數據庫的寫入權限,則它無法按預期工作。在這種情況下,結束消息期望文件已正確執行。有什麼方法可以確定遷移者是否退出了錯誤?

我想顯示:

  • 遷移代碼
  • (如果失敗),失敗的錯誤消息
  • (否則)成功消息

編輯:我本來問到如何顯示錯誤和一般輸出 - 這是通過>> install_log.txt 2>&1代碼實現的。現在我只需要弄清楚如何識別遷移時是否發生錯誤。

回答

0

我發現的溶液如下:

"%~dp0\FluentMigrator.1.1.2.1\tools\Migrate.exe" /conn "DATA SOURCE=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=%HostName%)(PORT=%ServerPort%))(CONNECT_DATA=(SERVICE_NAME=%ServiceName%)));PASSWORD=%installerUserPW%;PERSIST SECURITY INFO=True;USER ID=%installerUserName%;" /provider oracle /context %installerUserName% /assembly ./bin/Debug/DatabaseMigrations.dll >> migrate_log.txt 2>> migrateerror_log.txt 
if exist migrate_log.txt (
     if exist migrateerror_log.txt (
     TYPE migrateerror_log.txt >> install_log.txt 
     echo ------------------------------------------------------------------------------->> install_log.txt 
     echo -------------------------- Database Setup has failed ------------------------- >> install_log.txt 
     echo ------------------------------------------------------------------------------->> install_log.txt 
    ) else (
     echo ------------------------------------------------------------------------------->> install_log.txt 
     echo ----------------- Database Setup has completed successfully ------------------ >> install_log.txt 
     echo ------------------------------------------------------------------------------->> install_log.txt 
    ) 
) else (
    echo ------------------------------------------------------------------------------->> install_log.txt 
    echo ------------- An unexpected error has occurred in FluentMigrator ------------- >> install_log.txt 
    echo ------------------------------------------------------------------------------->> install_log.txt 
) 
相關問題