@@ -59,14 +59,14 @@ public void start(final Promise<Void> aPromise) {
5959 final JsonObject config = config ();
6060 final String [] cmd = { "which" , AUDIOWAVEFORM };
6161 final String cmdline = String .join (SPACE , cmd );
62- final ProcessBuilder pb = new ProcessBuilder (cmd ).redirectOutput (ProcessBuilder .Redirect .PIPE );
63-
6462 final String configErrorMsg ;
6563
64+ LOGGER .debug (MessageCodes .AVPT_011 , WaveformVerticle .class .getSimpleName (), Thread .currentThread ().getName ());
65+
6666 // Make sure that audiowaveform is installed on the system
6767
6868 try {
69- final Process which = pb .start ();
69+ final Process which = new ProcessBuilder ( cmd ) .start ();
7070 final int exitValue = which .waitFor ();
7171 final InputStream stdout ;
7272 final String cmdResult ;
@@ -202,30 +202,28 @@ private Future<ByteBuffer> audiowaveform(final Path anAudioFilePath) throws IOEx
202202 final String [] cmd = { AUDIOWAVEFORM , "--input-filename" , anAudioFilePath .toString (), "--output-format" , "dat" ,
203203 "--bits" , "8" };
204204 final String cmdline = String .join (SPACE , cmd );
205- final ProcessBuilder pb = new ProcessBuilder (cmd ).redirectOutput (ProcessBuilder .Redirect .PIPE );
206205
207206 try {
208- pb .start ().onExit ().thenAccept (subprocess -> {
209- try (InputStream stdout = subprocess .getInputStream ();
210- InputStream stderr = subprocess .getErrorStream ()) {
211-
212- final int exitValue = subprocess .exitValue ();
207+ final Process audiowaveform = new ProcessBuilder (cmd ).start ();
213208
214- if ( 0 == exitValue ) {
215- // Redact the binary audiowaveform data for logging
216- final String cmdResultMsg = LOGGER . getMessage ( MessageCodes . AVPT_015 , cmdline , exitValue ,
217- "[binary audiowaveform data]" );
209+ // Unless we read its output before calling `onExit()`, the audiowaveform process will stay asleep until it
210+ // receives an interrupt signal
211+ final byte [] stdout = audiowaveform . getInputStream (). readAllBytes ();
212+ final String stderr = new String ( audiowaveform . getErrorStream (). readAllBytes (), StandardCharsets . UTF_8 );
218213
219- LOGGER .debug (cmdResultMsg );
214+ audiowaveform .onExit ().thenAccept (process -> {
215+ final int exitValue = process .exitValue ();
220216
221- asyncResult .complete (ByteBuffer .wrap (stdout .readAllBytes ()));
222- } else {
223- final String errorOutput = new String (stderr .readAllBytes ());
224-
225- asyncResult .fail (LOGGER .getMessage (MessageCodes .AVPT_015 , cmdline , exitValue , errorOutput ));
217+ if (0 == exitValue ) {
218+ for (final String line : stderr .split ("\\ r?\\ n" )) {
219+ LOGGER .debug (line );
226220 }
227- } catch (final IOException details ) {
228- asyncResult .fail (LOGGER .getMessage (MessageCodes .AVPT_016 , cmdline , details ));
221+ // Redact the binary audiowaveform data for logging
222+ LOGGER .debug (MessageCodes .AVPT_015 , cmdline , exitValue , "[binary audiowaveform data]" );
223+
224+ asyncResult .complete (ByteBuffer .wrap (stdout ));
225+ } else {
226+ asyncResult .fail (LOGGER .getMessage (MessageCodes .AVPT_015 , cmdline , exitValue , stderr ));
229227 }
230228 });
231229 } catch (final IOException details ) {
0 commit comments