ProcessBuilder does not stop

前端 未结 2 373
逝去的感伤
逝去的感伤 2021-01-20 11:26

I am trying to decode an mp3 file to a wav file by using the ProcessBuilder class under Linux. For some reason the process does not stop so that I have to cancel it manually

相关标签:
2条回答
  • 2021-01-20 11:44

    It might be a lot easier for you to use a LAME Java wrapper like LAMEOnJ. That way you avoid spawning off processes and you can just interact with lame as if it were a Java library.

    0 讨论(0)
  • 2021-01-20 11:45

    You need to drain both the output (via getInputStream()) and error (via getErrorStream()) streams of the process, otherwise it may block.

    Quoting the Process documentation:

    Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.

    (which applies to both the error and output streams)

    You'll probably need to drain each stream in different threads because each may block when it has no data.

    0 讨论(0)
提交回复
热议问题