是否可以在Electron中调用本机进程?
例如,如果我想致电git
或类似的电话,可以吗?
示例:
var process = new Process();
process.executable = File.ApplicationDirectory() + "/utilities/my_process_not_node_js";
process.arguments = "-html=5 -include-css=true -mobile-support=true";
process.addEventListener("standardInput", handleInput);
process.run();
答案 0 :(得分:1)
当然,您可以访问完整的NodeJS内置API。
例如,如果您想执行一个简单的ls -lh /usr
命令,则可以执行以下操作:
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}`));