I'm using node@18.15.0
and pnpm@8.6.5
and sudo-prompt@9.2.1
. I have the following command I want to execute node ./test.cjs
, but with privileged permissions.
When I execute it without permissions, it works and I see logs.
This is the file content of test.cjs
script:
const sudoPrompt = require('sudo-prompt');
sudoPrompt.exec('node ./scripts/spawn-process.cjs', (error) => {
if (error) {
throw error;
}
});
then, the scripts/spawn-process.cjs
file content:
const { spawn } = require('node:child_process');
const spawner = spawn('webpack', ['--config', './webpack/webpack.config.dev.ts'], {
windowsHide: true,
shell: true,
stdio: 'pipe',
});
process.stdin.pipe(spawner.stdin);
spawner.stdout?.on('data', (data) => {
console.log(data);
});
spawner.stderr?.on('data', (data) => {
console.log(data);
});
spawner.on('close', (exitCode) => {
process.exit(exitCode);
});
Everything is working, the command is spawned successfully and running as required, but I don't see any output in the terminal from the console.log
. When I run the webpack
command as npm script: "test": "webpack --config ./webpack/webpack.config.dev.ts"
, and then running sudo pnpm test
(for example in macOS), I do see output in the console.