我可以在命令提示符 tasklist /fi "imagename ne siebde*" /fi "imagename eq sieb*" /svc | find "gtwyns"
下得到正確的輸出結果。批量轉義字符使用^
但是,如果我想在批處理文件中使用這個條件,我必須使用下面的命令來做到這一點。
for /f "tokens=2 delims= " %%a in ('tasklist /fi "imagename ne siebde*" /fi "imagename eq sieb*" /svc ^| find "gtwyns")
我需要理解^字符的功能,它是如何工作的?
我也想知道當它在批處理腳本中使用管道時是否會打開一個新的cmd?
你可以自己回答兩個問題。你已經經歷過在''''''for'命令前面需要'^'。原因是在通過執行之前逃避'|'字符並防止在蝙蝠中被解釋。當你執行它時,cmd窗口是否打開? –
@PA管道沒有打開一個新窗口,但它確實啓動了兩個新的cmd.exe實例(每個管道一端) – jeb
不,它不會打開一個新窗口..如果我詳細說明.. 在一個批處理文件中,如果我有以下代碼,我可以執行下面的命令而不使用^符號.. sc \\ EDCBSCSR4DE-001查詢siebsrvr_VIVO_SES_VIVO_SRVR |找到 「停止」 如果%ERRORLEVEL%= = 0( 轉到:停止 )其他( 轉到:停止 ) – learntolive