help icon indicating copy to clipboard operation
help copied to clipboard

No live data with spawn

Open etairl opened this issue 9 years ago • 5 comments

  • Node.js Version:
  • OS:
  • Scope (install, code, runtime, meta, other?):
  • Module (and version) (if relevant):

Version: 6.11.2 Platform: Win 64

Hi there, I'm using child_process with spawn. The command that I used is: var ls = require('child_process').spawn('cmd.exe', ['/c', COMMAND WITH FULL PATH); It executes just fine, it returns the data after the process is finished. However, I'm looking to get data streamed live back to the parent process. I'm using stdout, stderr and stdin but none of them streams the data live.

How can I get the data live using spawn (or any other child_process function)?

// I am an example of JS code
// please remove me too

-->

etairl avatar Oct 16 '17 09:10 etairl

It executes just fine, it returns the data after the process is finished. However, I'm looking to get data streamed live back to the parent process. I'm using stdout, stderr and stdin but none of them streams the data live.

Can you explain how you got to that conclusion?

addaleax avatar Oct 16 '17 09:10 addaleax

Hi and thank you for your reply.

Which conclusion would that be? That it executes fine or that the data is not streamed live?

etairl avatar Oct 16 '17 09:10 etairl

That the data arrives, but that it doesn’t arrive “live”? Like, how do you know it’s not just an operating system buffer that waits until enough data has been gathered or something like that?

addaleax avatar Oct 16 '17 09:10 addaleax

Well, if I execute the command from CMD, I get live stream output (which is dots presented on the screen - one dot for every second). But via nodejs I get them all in a single output once the command's finished.

etairl avatar Oct 16 '17 09:10 etairl

Can you give any more information about what kind of program you are running? At first I thought that the frct that you used ls in the code snippet means that you run, well, ls, but that doesn’t seem to be the case?

addaleax avatar Oct 16 '17 09:10 addaleax