2013-03-22 50 views
4

的文檔,Vim的system函數表示,這對第二個參數:如何使用系統的第二個參數(輸入)()函數

當{輸入}給出,這個字符串寫入一個文件,作爲stdin傳遞給命令。

我從明白那是什麼,如果你的system調用是這樣的:

call system('node something.js --file', 'here is some text') 

執行看起來像這樣的命令:

node something.js --file some/temp/file 

some/temp/file將有文字here is some text作爲其內容。爲了測試這個,我跑了Vim命令(第二行是結果):

:echo system('cat', 'here is some text') 
here is some text 

好吧,這看起來正確的。第二個測試:

:echo system('echo', 'here is some text') 
<blank line> 

而不是獲取一些臨時文件的名稱,我有一個空行。此外,當我在我的node.js腳本中打印process.argv時,我只得到['node', 'path/to/something.js', '--file']

我錯過了{input}參數如何使用?似乎爲cat工作,但不是echo或我自己的腳本?

+0

嘿downvoter。介意告訴我如何改善我的問題? – benekastah 2013-09-03 18:46:34

回答

4

你錯了;執行的命令是

node something.js --file some/temp/file 

而是

echo "some/temp/file" | node something.js --file 

或更好

node something.js --file < some/temp/file 

如果你想作爲參數傳遞的文字,只是把這段的system()的第一個參數(通過shellescape()正確逃脫)。

相關問題