2

I'm trying to run this sox command to mix several audio inputs from my program using:

String command = "sox C:/serverFolder/a1.wav -p pad 0 0 | sox - -m C:/serverFolder/a2.wav -p pad 10.0 0 | sox - -m C:/serverFolder/a3.wav -p pad 0 0 | sox - -m C:/serverFolder/a4.wav -p pad 20.0 0 |  sox - -m -v 0 C:/serverFolder/blank.wav C:/serverFolder/audioFile.wav";
Process proc = Runtime.getRuntime().exec(command);

I get

sox FAIL pad: usage: {length[@position]}

if I run this command into my cmd it runs fine. I tried several approaches like the one suggested here with the List: Using Java's ProcessBuilder to run SoX

Or the one suggested here using the absolute path to sox Running Sox commands from Java code

Since the code runs fine in cmd I'm guessing I'm sending it in a bad way from java. Any thoughts?

Community
  • 1
  • 1
bruno
  • 21
  • 2
  • You're trying to make Process run a pipe, which is a shell construct. If you want to execute a pipe you should run your command under some shell that's capable of executing a pipe, like [explained here for a unix-y os](http://stackoverflow.com/questions/8243157/building-a-process-pipe-with-processbuilder-in-java-7) but more or less the same thing should be possible with Windows' cmd. – fvu Nov 28 '13 at 21:54
  • 1
    Thanks fvu that made sense. I changed the command to be: `String[] command = new String[]{"cmd.exe","/c sox C:/serverFolder/a1.wav -p pad 0 0 | sox - -m C:/serverFolder/a2.wav -p pad 10.0 0 | sox - -m C:/serverFolder/a3.wav -p pad 0 0 | sox - -m C:/serverFolder/a4.wav -p pad 20.0 0 | sox - -m -v 0 C:/serverFolder/blank.wav C:/serverFolder/audioeFile.wav"}` `Process proc = Runtime.getRuntime().exec(command);` and worked fine. Thanks for your time! – bruno Nov 28 '13 at 22:25
  • yw :) May I suggest you post your solution as an answer, and accept it? That way future visitors can see a valid solution to the problem. – fvu Nov 28 '13 at 23:21
  • @fuv I was planning on doing that but I found that the command even though it runs fine and creates a new file doesn't work as expected. – bruno Dec 03 '13 at 02:27
  • @fuv I was planning on doing that but I found that the command even though it runs fine and creates a new file doesn't work as expected. The pads are not working. The audios start at second: a1 - 10s a2 - 20s a3 - 20s a4 - 20s Where the pads are: a1.wav -p pad 0 0 a2.wav -p pad 10.0 a3.wav -p pad 0 0 a4.wav -p pad 20.0 0 any thoughts ? Should I create a new question?? Thanks again – bruno Dec 03 '13 at 02:38
  • Does that pipeline work correctly if you run it from the command line? Normally there shouldn't be any difference in what calling cmd programmatically does, and how it behaves interactively. There may be a difference between how Unix/Linux shells run pipes, and how windows does it though, I'm not sure. – fvu Dec 03 '13 at 12:07
  • @fuv the same happens if I run the command from cmd. But this is not expected right? I already created a new question but hasn't got any atention. http://stackoverflow.com/questions/20342180/sox-pad-not-working-as-expected – bruno Dec 03 '13 at 19:50
  • Thankyou guys! In windows be aware with double quotes (new String[] {"\"cmd.exe","/c\" " + soxScript}). Any path should be with double quotes – Gilian Jul 17 '16 at 17:41

0 Answers0