I am creating a child_process which will just open a command prompt whenever user click on a Button. If user clicks on the button 3 times. then 3 times a command prompt is created. Instead of creating 3 command prompt, I want to show the already created process(command prompt), means I want only one instance of command prompt.
const { exec } = require('child_process');
export async function executeCommand(commandLine, execOptions) {
return await new Promise((resolve, reject) => {
if (execOptions.env) {
for (var prop in execOptions.env) {
if (execOptions.env.hasOwnProperty(prop)) {
process.env[prop] = execOptions.env[prop];
}
}
delete execOptions.env;
}
exec(commandLine, execOptions, (error, stdout, stderr) => {
console.debug(stdout);
if (error) {
console.debug(stderr);
console.debug(error);
reject(error);
}
else if (stderr) {
console.debug(stderr);
reject(stderr);
}
else {
resolve(stdout);
}
});
});
}
Please help me in solving this issue.