I'm trying to fix a bug for a VSCode extension (twsx.vs.language.cmake) which uses NodeJS child_process
to capture stdout from cmake commands to provide VSCode with auto-completion data. The problem is that child_process.stdout.on('data',...)
is never invoked for any cmake command.
environment:
I created a simple test script for the problem:
var spawn = require('child_process').spawn;
var cmd = spawn("cmake", ["--help-command-list"]);
cmd.stdout.on('data', (data) => console.log(`Stdout: ${data}`));
cmd.stderr.on('data', (data) => console.log(`Stderr: ${data}`));
cmd.on('error', (err) => console.log(`Error: ${err}`));
cmd.on('close', (code, signal) =>
console.log(`Close; code: ${code}; signal: ${signal}`));
The script above
Executing cmake directly inside a VSCode terminal works as expected.
Question: How is it possible that child_process.spawn("cmake").stdout.on('data', ...)
behaves different inside VSCode terminal and a native terminal ?
This strange behavior is happening due to CMake being installed from snapcraft. It seems the app armor profiles somehow break file descriptors and thus lead to this strange bug (more about that here).
The solution is to install cmake from other sources than snapcraft.