1

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 ?

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
SuperEwald
  • 83
  • 6
  • What's the purpose of `console.log` in the extension? Just for debug logging? If so, why not use an output channel as described in [How to write to log from vscode extension?](/q/34085330/11107541). As for why it's not working, can you please [edit] your post to add what you see from the `error` event? See [the docs at "Example of checking for failed spawn:"](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options). – starball Jan 19 '23 at 19:06
  • The snippet is just a test script and not from the extension itself. It does reproduce the problem, the logs are needed to see whether there is data retrieved or not. I updated the my question to include error event, stderr and exit code check. All of them are fine. – SuperEwald Jan 20 '23 at 11:01

1 Answers1

1

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.

SuperEwald
  • 83
  • 6