karolyzz
karolyzz

Reputation: 510

Execute unix executables (python) in Electron

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:

const spawn = require("child_process").spawn; const pythonProcess = spawn("path/to/script", arg1, arg2);

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

Answers (1)

Janith
Janith

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

Related Questions