javascript - Node : ShellJS not working with command line tools

标签 javascript node.js bash shell

如果我执行 shell.exec('http'),我会得到 httpie 的帮助,这是我使用的一个请求库。但是,如果我添加一个参数,如下所示,shelljs 永远不会调用回调。

var shell = require('shelljs');

shell.exec('http http://www.example.com/', {async: true, silent: false}, function(data){
  console.log(data);
})

如果我使用 curl 而不是 http,上面的例子确实有效。有什么想法为什么它不能与 http 一起使用吗?

最佳答案

添加ignore-stdin选项

var shell = require('shelljs');
shell.exec('http --ignore-stdin http://www.example.com/', {async: true, silent: false}, function(data){
  console.log(data);
});

--ignore-stdin 选项阻止 HTTPie 从标准输入读取数据,这在非交互式调用期间通常是不可取的。

您可以在 httpie 的脚本部分阅读更多内容

关于javascript - Node : ShellJS not working with command line tools,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31994967/

相关文章:

javascript - Jest Spy 说函数没有被调用

javascript - 提交按钮不发送任何内容

node.js - 在 docker 容器中永远启动 Node 时出错

bash - 在 shell 脚本中分组

linux - 有没有办法在 Linux 中将参数分组到命令中?

javascript - Backbone - 在多个事件后渲染 View

javascript - 使用 JQuery 动态删除 DIV

javascript - 不考虑 puppeteer 输入字段

node.js - 使用 async/await 冒泡和捕获异常的正确模式是什么?

python - 从文件中提取一级邻居