1

I try to execute some simple bash in node bu get an error: /usr/bin/file: /usr/bin/file: cannot execute binary file

'use strict';

var spawn = require('child_process').spawn;

var process = spawn('bash', ['file']);
process.stdout.on('data', function(data){
    console.log(data.toString());
});
process.stderr.on('data', function(data){
    console.log(data.toString());
});

I even gave the script chmod+x and i run it with node script.js

Any ideas?

1 Answer 1

2

It looks like when you're spawning the child process, you're actually trying to run the "file" command, not a shell script, so bash is barking at you.

It would be equivalent to typing this on the command line: "bash file".

You'll want to write a shell script and pass that as the parameter to the bash process.

So, write a script called "do_something.sh" and then run your code with ['do_something.sh'] as the parameter to bash rather than ['file']:

var process = spawn('bash', ['do_something.sh']);
Sign up to request clarification or add additional context in comments.

1 Comment

And make sure you've done chmod +x on do_something.sh, of course and that it's in your path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.