2013-03-22 49 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()正确逃脱)。

相关问题