views:

167

answers:

1

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 piping 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.

+1  A: 

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.

hlovdal
hmmm, right now I can read the console out but from stderr and I have to use CMD /C <command> to stream from it. I guess this answers my question
ken
oh, follow up question. Now I can't kill the spawned sox. process.destroy won't work
ken