不断从subprocessstdout读取json
我想阅读和jjj消息发送到一个Javasubprocessnodejs和。 孩子的过程会活一段时间。 通过stdio
发送和接收的消息表示来自两个进程的事件。 因此,消息必须在完成后立即处理。
输出将在表格中
{"type":"eventType","data":...} {"type":"anotherEventType","data":...} ... {"type":"anotherEventType","data":...}
写信息是没有问题的,但阅读是。 特别是因为我不能依赖\n
分裂的消息,也不能说一个块只包含一个消息。
不幸的是,我能find的每个例子都会cachingstdout
的输出,直到进程终止并且只parsing它。 而我可以find的所有IPC节点模块都使用我想避免的套接字。
是否有现有的库提供这样的function,或者我必须自己的angular色?
JSONStream正是我想要的。
child.stdout .pipe(require('JSONStream').parse()) .on('data', processMessage);