我試圖用批處理腳本自動加載Putty Pageant與一些SSH密鑰,但是因爲我想繞過已經運行的Pageant的錯誤消息,所以我將它放在IF語句中。然而,對於某些原因,這是行不通的:這個批處理腳本的語法有什麼問題?
tasklist /FI "IMAGENAME eq pageant.exe" 2>NUL | find /I /N "pageant.exe">NUL
if %ERRORLEVEL%==1 (:: checks whether pageant.exe is running or not
:: set the SSH-keys
if exist "C:\SSH keys\key1.ppk" (set KEYS="C:\SSH keys\key1.ppk")
if exist "C:\SSH keys\key2.ppk" (set KEYS=%KEYS% "C:\SSH keys\key2.ppk")
if not defined KEYS (
msg * A SSH-key is propably missing.
)
:: Start pageant with the defined SSH-keys
start /d"C:\Program Files (x86)\PuTTY" pageant.exe %KEYS%
)
雖然他們分開工作: (1)
tasklist /FI "IMAGENAME eq pageant.exe" 2>NUL | find /I /N "pageant.exe">NUL
if %ERRORLEVEL%==1 (:: checks whether pageant.exe is running or not
:: This works!
start /d"C:\Program Files (x86)\PuTTY" pageant.exe
)
(2)
:: set the SSH-keys
if exist "C:\SSH keys\key1.ppk" (set KEYS="C:\SSH keys\key1.ppk")
if exist "C:\SSH keys\key2.ppk" (set KEYS=%KEYS% "C:\SSH keys\key2.ppk")
if not defined KEYS (
msg * A SSH-key is propably missing.
)
This works as well!
start /d"C:\Program Files (x86)\PuTTY" pageant.exe %KEYS%
它是一個語法問題?
一種工作#1? –
@GuyThomas堆棧溢出並不是特別滿意的問題,只是由代碼和修復請求組成。 OP應該說明究竟是什麼失敗,而不是說「它不起作用」,並顯示他們已經把問題縮小到了什麼程度。批處理腳本問題在這裏是主題,不需要遷移,特別是當涉及編寫甚至不需要編程(例如PuTTy)的軟件的腳本時。 – slhck