Reputation: 510
I have the following file structure:
--backend/
---script (unix executable)
--src/
---script_launcher.js
---main.js
--all other necessary files
script
is a unix executable which I built from python script using pyinstaller
. script_launcher.js
should start the unix executable script
, pass arguments through standard input to it and listen to: any standard output/any errors/when the script is finished executing. Before unix executable I had a .py
file in its place which I would call using python-shell npm module from script_launcher.js
. I know I should use child-processes
but then:
spawn
seems to only work on python scripts and not on unix executables (doesn't allow me to execute script
) const spawn = require("child_process").spawn;
const pythonProcess = spawn("path/to/script", arg1, arg2);
exec
or execFile
seems to not allow me read info that I described above in the way that python-shell
lets me read info.What would be the best approach to this problem to call unix executables? Also, when calling them, should I use path as /path/to/script
or /path/to/script.exec
? I don't really understand whether script
has a filename extension or not.
Upvotes: 0
Views: 574
Reputation: 2910
Just pass the executable locations and the command line arguments
const unixProcess = spawn('path/to/executable',[arg1, arg2, arg3, ...]);
Example
const unixProcess = spawn('/usr/bin/whoami',[arg1, arg2, arg3, ...]);
Upvotes: 1