I'm running an electron app with Wraith. I'm using node's child_process and it works really well except for cancelling a bash script/command.
I haven't been able to find a solution that works for me online.
I want to run a command that would essentially operate similar to ctrl + c but from my Electron app.
I've stripped down my code to make it easier to read:
My index.js file
var electron = require("electron");
var ipc = electron.ipcRenderer;
var shell = require('electron').shell;
var remote = require('electron').remote
var fs = require('fs');
var path = require('path');
var spawn = require('child_process').spawn;
function runScript(index) {
var directory = __dirname + '/src/bash/';
// Works as expected
var vrt = spawn('/bin/sh',
[directory + task, arg1, arg2]);
vrt.stdout.on('data', function (data) {
console.log(data.toString())
});
//This doesn't work
setTimeout(function () {
console.log("should close")
vrt.kill();
}, 1000)
}
The console.log confirms that the script continues running even though vrt.kill() has been called.
This method has popped up several times during my search for answers. Does anyone have an idea of what am I doing wrong?
Thanks, All
Your help is much appreciated
Moe