【发布时间】:2017-12-05 10:54:39
【问题描述】:
我正在尝试在 node.js 中使用 child_process 模块和树莓派上的 mpg123 播放器制作一个 mp3 网络广播。
问题来了: 当我尝试写入流时,我总是得到一个错误:
Error: write EPIPE
at exports._errnoException (util.js:1026:11)
at WriteWrap.afterWrite (net.js:795:14)
这是我尝试测试的内容:
//create a subprocess
var test = childProcess.exec('ls /home/pi/music');
//pipe all the output to the process output
test.stdout.pipe(process.stdout);
test.stderr.pipe(process.stderr);
test.stdin.setEncoding('utf-8');
//here I just want to write a key to the subprocess
test.stdin.write('q');
test.stdin.end()
任何人都知道,要做什么,创建的写入流在一切完成之前不会关闭?
当然,我仍然在 google 上搜索过这个:
Child_process throw an Error: write EPIPE
https://github.com/nodejs/node/issues/2985
https://nodejs.org/api/child_process.html#child_process_subprocess_stdin
https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback
请帮忙!
【问题讨论】:
-
''ls /home/pi/music' 的子进程在您尝试在其输出上写入其他内容之前不会退出?
-
我认为进程将退出,这就是错误的原因。但我不知道如何stop 这个:c。如果它不停止,我认为它不会产生错误......
-
不是因为你
.end()stnd 流,而它已经在另一边结束了吗? -
你的意图是什么,如果你想测试你可以生成一个更大的输出来测试行为(比如说'dmesg')。你想播放mp3文件,为什么不配置播放器输出到stdout?
标签: javascript node.js child-process