Files

47 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

const childProcess = require('node:child_process');
const originalExec = childProcess.exec;
childProcess.exec = function patchedExec(command, options, callback) {
const normalizedCommand = typeof command === 'string' ? command.trim().toLowerCase() : '';
try {
return originalExec.call(this, command, options, callback);
} catch (error) {
if (normalizedCommand === 'net use' && error && error.code === 'EPERM') {
const cb =
typeof options === 'function'
? options
: typeof callback === 'function'
? callback
: null;
if (cb) {
process.nextTick(() => cb(error, '', ''));
}
return {
pid: undefined,
killed: false,
kill() {
return false;
},
on() {
return this;
},
once() {
return this;
},
emit() {
return false;
},
removeListener() {
return this;
}
};
}
throw error;
}
};