How to pass STDIN to node.js child process

前端 未结 4 1604
面向向阳花
面向向阳花 2020-12-07 01:10

I\'m using a library that wraps pandoc for node. But I can\'t figure out how to pass STDIN to the child process `execFile...

var execFile = requ         


        
4条回答
  •  醉梦人生
    2020-12-07 01:29

    Here's how I got it to work:

    var cp = require('child_process');
    var optipng = require('pandoc-bin').path; //This is a path to a command
    var child = cp.spawn(optipng, ['--from=markdown', '--to=html']); //the array is the arguments
    
    child.stdin.write('# HELLO'); //my command takes a markdown string...
    
    child.stdout.on('data', function (data) {
        console.log('stdout: ' + data);
    });
    child.stdin.end();
    

提交回复
热议问题