加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

vim – 如何使用system()函数的第二个参数(输入)

发布时间:2020-12-15 21:06:27 所属栏目:安全 来源:网络整理
导读:vim系统函数的文档说明了第二个参数: When {input} is given,this string is written to a file and passed as stdin to the command. 我从中理解的是,如果您的系统调用如下所示: call system('node something.js --file','here is some text') 执行的命令
vim系统函数的文档说明了第二个参数:

When {input} is given,this string is written to a file and passed as stdin to the command.

我从中理解的是,如果您的系统调用如下所示:

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

执行的命令如下所示:

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

并且一些/ temp /文件将使这里的文本是一些文本作为其内容.为了测试这个,我运行了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}参数,我错过了什么?为什么它似乎适用于猫,但不是回声或我自己的脚本?

解决方法

你错了;执行的命令不是

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

反而

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

或更好

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

如果您希望将文本作为参数传递,只需将其附加到system()的第一个参数(通过shellescape()正确转义).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读