使用 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 ")
並且,在任何循環、列印或使用字串函數中使用該變數。