如果我执行 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/