1

I have a nodejs script that runs a python program. I'd like to be able to interact with pdb when the debug sessions starts.

I'm using this to start my process:

  var cp = require('child_process')
  var app = cp.spawn('python_app', ['param'])
  app.stdout.pipe(process.stdout)
  app.stderr.pipe(process.stderr)                         
  process.stdin.pipe(app.stdin)

Unfortunately, when the debug session starts, I don't see anything and the process simply hang. I guess pdb/ipdb is working but it doesn't seem that anything I do is sent to pdb.

Is it possible to interact with pdb from nodejs?

Loïc Faure-Lacroix
  • 13,220
  • 6
  • 67
  • 99

1 Answers1

1

Ok, I found how to do that...

Instead of piping stream manually, the child_proccess library as an option that seems to just do what I need.

The documentation:

https://nodejs.org/api/child_process.html#child_process_options_stdio

The code becomes:

var cp = require('child_process')
var app = cp.spawn('python_app', ['param'], {stdio: [0,1,2]})

Nothing else is required. It's unclear what does it change to spawn the process like that or later pipe IOs. But this method works and the other doesn't.

My guess is that if we use directly the same file descriptor by passing the file descriptor id. We aren't streaming data from one fd to an other. Which means that everything that is sent to stdin will get to the next program, and anything from stderr or stdout will get from the program to the terminal. That said, if we were streaming data from one fd to an other, we might not be transferring everything. Terminal have some special instructions and they might not get passed to stdin or stdout,stderr while piping.

This answer is quite specific to NodeJS but I guess that if we were doing the same thing from python to python, we'd have to do the same thing with subprocess by passing sys.[stdin, stdout, stderr].

Loïc Faure-Lacroix
  • 13,220
  • 6
  • 67
  • 99