Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node: ShellJS not working with command line tools

If I execute shell.exec('http') I get the help for httpie, a request library I use. However if I add an argument, like seen below, shelljs never calls the callback.

var shell = require('shelljs');

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

The above example DOES work if I use curl instead of http. Any ideas why its not working with http?

like image 470
Daniel Rasmuson Avatar asked Apr 21 '26 03:04

Daniel Rasmuson


1 Answers

Add ignore-stdin option

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

The --ignore-stdin option prevents HTTPie from reading data from stdin, which is usually not desirable during non-interactive invocations.

You can read more in the Scripting section of httpie

like image 148
Medet Tleukabiluly Avatar answered Apr 23 '26 17:04

Medet Tleukabiluly