开发者

Capture console text of piped app to another app

开发者 https://www.devze.com 2022-12-21 06:43 出处:网络
I\'m sorry if the title is quite confusing but I am wondering if it\'s possible to get the stdout of an app that is piped into another app in java.

I'm sorry if the title is quite confusing but I am wondering if it's possible to get the stdout of an app that is piped into another app in java.

Here's the commandline.

sox -d -t wav - | lame - test.mp3

If this is executed in bash, this is the output.

Input File     : '/dev/dsp' (ossdsp)
Channels       : 2
Sample Rate    : 48000
Precision      : 16-bit
Sample Encoding: 16-bit Signed Integer PCM

In:0.00% 00:00:25.00 [00:00:00.00] Out:1.20M [     -|=-    ]        Clip:0

The last line gets updated by sox until user sends SIGINT.

Problem is, in java, InputStream from that process does not produce any data. But if I omit the pi开发者_C百科ping of sox to lame, sox -d -t wav test.wav, InputStream gets data. My question is, what happened to the console out? How can I get access to it.


When bash start executing sox -d -t wav - | lame - test.mp3, because of the pipe character bash will fork two processes to execute each command, and then connects stdout from the first process with stdin to the second one. Bash will not do anything specific with stderr of either process, so the screen output you see from sox (Input File ...) is not part of the pipe operation.

From what I can understand from your question, you have one java program that starts those two sox and lame processes. More details about how you are doing this would be good. But in any case to get the screen output you showed example of you have to read stderr from the sox process.

0

精彩评论

暂无评论...
验证码 换一张
取 消