@@ -48,7 +48,10 @@ private void exec(String command, String... envp) {
4848 return ;
4949
5050 try {
51- int exitCode = runtime .exec (command .trim (), envp ).waitFor ();
51+ Process p ;
52+ if (conf .executeWithBash ) p = runtime .exec (new String []{"/bin/bash" , "-c" , command .trim ()}, envp );
53+ else p = runtime .exec (command .trim (), envp );
54+ int exitCode = p .waitFor ();
5255 LOGGER .trace ("Executed shell command: {} -> {}" , command , exitCode );
5356 } catch (IOException | InterruptedException ex ) {
5457 LOGGER .error ("Failed executing command: {}" , command , ex );
@@ -128,6 +131,7 @@ public void onConnectionEstablished() {
128131
129132 public static class Configuration {
130133 public final boolean enabled ;
134+ public final boolean executeWithBash ;
131135 public final String onContextChanged ;
132136 public final String onTrackChanged ;
133137 public final String onPlaybackEnded ;
@@ -141,10 +145,11 @@ public static class Configuration {
141145 public final String onConnectionDropped ;
142146 public final String onConnectionEstablished ;
143147
144- public Configuration (boolean enabled , String onContextChanged , String onTrackChanged , String onPlaybackEnded , String onPlaybackPaused ,
148+ public Configuration (boolean enabled , boolean executeWithBash , String onContextChanged , String onTrackChanged , String onPlaybackEnded , String onPlaybackPaused ,
145149 String onPlaybackResumed , String onTrackSeeked , String onMetadataAvailable , String onVolumeChanged ,
146150 String onInactiveSession , String onPanicState , String onConnectionDropped , String onConnectionEstablished ) {
147151 this .enabled = enabled ;
152+ this .executeWithBash = executeWithBash ;
148153 this .onContextChanged = onContextChanged ;
149154 this .onTrackChanged = onTrackChanged ;
150155 this .onPlaybackEnded = onPlaybackEnded ;
@@ -161,6 +166,7 @@ public Configuration(boolean enabled, String onContextChanged, String onTrackCha
161166
162167 public static class Builder {
163168 private boolean enabled = false ;
169+ private boolean executeWithBash = false ;
164170 private String onContextChanged = "" ;
165171 private String onTrackChanged = "" ;
166172 private String onPlaybackEnded = "" ;
@@ -182,6 +188,11 @@ public Builder setEnabled(boolean enabled) {
182188 return this ;
183189 }
184190
191+ public Builder setExecuteWithBash (boolean executeWithBash ) {
192+ this .executeWithBash = executeWithBash ;
193+ return this ;
194+ }
195+
185196 public Builder setOnContextChanged (String command ) {
186197 this .onContextChanged = command ;
187198 return this ;
@@ -244,7 +255,7 @@ public Builder setOnConnectionEstablished(String command) {
244255
245256 @ NotNull
246257 public Configuration build () {
247- return new Configuration (enabled , onContextChanged , onTrackChanged , onPlaybackEnded , onPlaybackPaused , onPlaybackResumed ,
258+ return new Configuration (enabled , executeWithBash , onContextChanged , onTrackChanged , onPlaybackEnded , onPlaybackPaused , onPlaybackResumed ,
248259 onTrackSeeked , onMetadataAvailable , onVolumeChanged , onInactiveSession , onPanicState , onConnectionDropped , onConnectionEstablished );
249260 }
250261 }
0 commit comments