![VIM:檢查外部程式是否正在執行的函數](https://rvso.com/image/89153/VIM%EF%BC%9A%E6%AA%A2%E6%9F%A5%E5%A4%96%E9%83%A8%E7%A8%8B%E5%BC%8F%E6%98%AF%E5%90%A6%E6%AD%A3%E5%9C%A8%E5%9F%B7%E8%A1%8C%E7%9A%84%E5%87%BD%E6%95%B8.png)
使用 vim 函數,我想使用 pgrep 檢查程式是否正在運行,如果沒有運行則執行某些操作。特別是,我想實現這樣的目標:
function! checkifrunning(mystring)
if 'pgrep "mystring"' shows that something is NOT running
--do something--
endif
endfunction
我的猜測是我需要使用“system()”函數,但我不確定如何使用。有人可以幫忙嗎?
編輯:我想要一個特別使用 pgrep 的解決方案,而不是其他方式
答案1
答案2
你可以使用像
:call system("pgrep process name ")
要列印輸出,
:echo system("pgrep process name ")
您可以將輸出儲存在變數中,例如
:let a=system("pgrep process name ")
並且,在任何循環、列印或使用字串函數中使用該變數。