简体   繁体   English

无法从子进程获取输出

[英]Unable to get output from child process

So, I have a simple app (I have written) which writes to stdout . 因此,我有一个简单的应用程序(已编写),该应用程序可以写入stdout

When I run it by itself, the output is being printed fine. 当我自己运行它时,输出可以正常打印。

Now, when I spawn the process with node... nothing happens (apart from a message saying the process has finished) 现在,当我使用节点生成流程时...什么都没有发生(除了一条消息,指出流程已完成)

Here's my code: 这是我的代码:

var spawn = require('child_process').spawn;
helper = spawn("myApp", []);
helper.stdout.on('data', function(data) { 
    console.log("GOT: " + data);
});
helper.stdout.on('end', function(data) {
    console.log("FINISHED: " + data);
});
helper.on('exit', function(code) {
    console.log("CLOSED!");
});

And here's the output: 这是输出:

FINISHED: undefined
CLOSED!

Yep, just that. 是的,就是那样。

What's going on? 这是怎么回事? Am I missing something? 我想念什么吗?

Make sure your stdio output buffers are being flushed in your application: 确保在您的应用程序中刷新了stdio输出缓冲区:

  fflush(stdout); // or something like that

Output straight to the tty has less buffering than output to a pipe. 直接输出到tty的缓冲少于输出到管道的缓冲。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从子进程输出字符串中提取变量 - Extract variables from child process output string NodeJS 在 raspi 上使用命令 df -h 从 child_process 获取 output - NodeJS get output from child_process with command df -h on raspi 如何获取在nodejs中使用child_process执行的命令的输出? - How to get the output of command executed using child_process in nodejs? 当将child_process.spawn()方法与{stdio:'inherit'}一起使用时,父级是否有可能从子进程接收输出? - When using the child_process.spawn() method with {stdio: 'inherit'}, is it possible for the parent receive output from the child process? Node.js如何从流程ID获取子流程 - Nodejs how to get child process from process Id 从Node.js获取子生成的进程的进度输出 - Getting the progress output of a child spawned process from nodejs HTML中的nodeJS child_process的样式输出 - Style output from a nodeJS child_process in html 节点子进程生成的输出与终端不同 - Node child process spawn output is different than from terminal 有没有办法从 child_process.execFile 生成的 python 脚本中获取“实时”output 行,而无需每次都刷新标准输出? - Is there a way to get 'live' output lines from a python script spawned by child_process.execFile without flushing stdout every time? 在Windows OS上使用child_process.spawn启动bat时如何从NodeJS获取输出,并且该bat将打开一个新终端 - How to get the output from NodeJS when use the child_process.spawn to launch a bat on windows OS, and the bat will open a new terminal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM