How to provide a path to child_process.spawn
For example the path:
c:\users\marco\my documents\project\someexecutable
The path is provided by the enduser from a configuration file.
var child_process = require('child_process');
var path = require('path');
var pathToExecute = path.join(options.toolsPath, 'mspec.exe');
child_process.spawn(pathToExecute, options.args);
Currently only the part after the space is used by child_process.spawn
I also tried by adding quotes arround the path like this:
var child_process = require('child_process');
var path = require('path');
var pathToExecute = path.join(options.toolsPath, 'mspec.exe');
child_process.spawn('"' + pathToExecute + '"', options.args);
However this results in a ENOENT
error.
As per https://github.com/nodejs/node/issues/7367#issuecomment-229728704 one can use the { shell: true }
option.
For example
const { spawn } = require('child_process');
const ls = spawn(process.env.comspec, ['/c', 'dir /b "C:\\users\\Trevor\\Documents\\Adobe Scripts"'], { shell: true });
Will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With