我正在尝试使用带有批处理脚本的一些 SSH 密钥自动加载 Putty Pageant,但是因为我想绕过它已经在运行的 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%
是语法问题吗?