Search code examples
node.jsvisual-studio-codecmakechild-process

NodeJS child_process.stdout empty inside VSCode terminal


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:

  • OS: Kubuntu 22.04
  • VSCode: 1.74.3 (snap)
  • CMake: 3.25.2 (snap)

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

  • does work outside of VSCode (using any terminal)
  • does work for any application but cmake inside VSCode terminal
  • does not work inside VSCode terminal (no errors, success exit code but no stdout data captured)

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 ?


Solution

  • 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.