Node.js: Capture STDOUT of `child_process.spawn`

前端 未结 3 930
-上瘾入骨i
-上瘾入骨i 2021-01-05 05:24

I need to capture in a custom stream outputs of a spawned child process.

child_process.spawn(command[, args][, options])

F

3条回答
  •  我在风中等你
    2021-01-05 05:54

    Hi I'm on my phone but I will try to guide you as I can. I will clarify when near a computer if needed

    What I think you want is to read the stdout from a spawn and do something with the data?

    You can give the spawn a variable name instead of just running the function, e.g:

    var child = spawn();
    

    Then listen to the output like:

    child.stdout.on('data', function(data) {
        console.log(data.toString());
    });
    

    You could use that to write the data then to a file or whatever you may want to do with it.

提交回复
热议问题