2

I'm using NodeJS childprocess to run shell commands on NodeJS / Express server (localhost). Everything goes well with basic shell commands like 'ls' (from NodeJS documentation):

const { spawn } = require('child_process');
const ls = spawn('ls', ['-lh', '/usr']);

ls.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});

ls.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});

ls.on('close', (code) => {
console.log(`child process exited with code ${code}`); 
});

Now, what I need to do is run a binary file that has shared object dependencies. The objects are located inside server folder 'public/libraries'. I've tried to modify the previous with

const runBinary = spawn('/path/to/binary/file', ['-someoption', 'public/libraries']);

The error message is 'error while loading shared libraries ... no such file or directory', meaning the shared objects are not found. I have no idea how to

1) tell 'runBinary' the location of the folder of shared objects, and then

2) run the binary successfully to create output in console.

I have all the necessary tools installed to run the binary in a Bash shell and have tested it works as it should.

Any ideas?

1 Answer 1

3

You can fix this by setting the environment variable LD_LIBRARY_PATH to the absolute path of your public/libraries directory.

Something like this:

spawn('/path/to/binary/file', ['-someoption'],
      {env: {LD_LIBRARY_PATH: '/path/to/public/libraries'}})
Sign up to request clarification or add additional context in comments.

1 Comment

@R.Järvinen: You're welcome. You can accept this answer by clicking the checkmark on the left. Welcome to Stack Overflow.

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.