在 Electron 中执行 unix 可执行文件 (python)
Execute unix executables (python) in Electron
我有以下文件结构:
--backend/
---script (unix executable)
--src/
---script_launcher.js
---main.js
--all other necessary files
script
是我使用 pyinstaller
从 python 脚本构建的 unix 可执行文件。 script_launcher.js
应该启动 unix 可执行文件 script
,通过标准输入将参数传递给它并收听:任何标准 output/any errors/when 脚本已完成执行。在 unix 可执行文件之前,我在它的位置有一个 .py
文件,我将使用 script_launcher.js
中的 python-shell npm module 调用它。我知道我应该使用 child-processes
但是然后:
spawn
似乎只适用于 python 脚本而不适用于 unix 可执行文件(不允许我执行 script
)
const spawn = require("child_process").spawn;
const pythonProcess = spawn("path/to/script", arg1, arg2);
exec
或 execFile
似乎不允许我以 python-shell
允许我阅读信息的方式阅读上面描述的信息。
解决此问题以调用 unix 可执行文件的最佳方法是什么?另外,在调用它们时,我应该使用路径作为 /path/to/script
还是 /path/to/script.exec
?我不太明白 script
是否有文件扩展名。
只需传递可执行文件位置和命令行参数
const unixProcess = spawn('path/to/executable',[arg1, arg2, arg3, ...]);
示例
const unixProcess = spawn('/usr/bin/whoami',[arg1, arg2, arg3, ...]);
我有以下文件结构:
--backend/
---script (unix executable)
--src/
---script_launcher.js
---main.js
--all other necessary files
script
是我使用 pyinstaller
从 python 脚本构建的 unix 可执行文件。 script_launcher.js
应该启动 unix 可执行文件 script
,通过标准输入将参数传递给它并收听:任何标准 output/any errors/when 脚本已完成执行。在 unix 可执行文件之前,我在它的位置有一个 .py
文件,我将使用 script_launcher.js
中的 python-shell npm module 调用它。我知道我应该使用 child-processes
但是然后:
spawn
似乎只适用于 python 脚本而不适用于 unix 可执行文件(不允许我执行script
)
const spawn = require("child_process").spawn;
const pythonProcess = spawn("path/to/script", arg1, arg2);
exec
或execFile
似乎不允许我以python-shell
允许我阅读信息的方式阅读上面描述的信息。
解决此问题以调用 unix 可执行文件的最佳方法是什么?另外,在调用它们时,我应该使用路径作为 /path/to/script
还是 /path/to/script.exec
?我不太明白 script
是否有文件扩展名。
只需传递可执行文件位置和命令行参数
const unixProcess = spawn('path/to/executable',[arg1, arg2, arg3, ...]);
示例
const unixProcess = spawn('/usr/bin/whoami',[arg1, arg2, arg3, ...]);