0

This question is related to the answer to this question:

Batch measurements of .wav files with sox stats

I have a similar problem and was happy to see what looked like a fairly solid solution already on stackoverflow. However I discovered R for the first time and downloaded R Command to try but I am getting only error messages when I try to execute this code in the R Commander interpreter:

spam = system("sox foo2.wav -n stat 2>&1", intern = TRUE)

If I add a foo2.wav file in the sox containing folder the error is:

running command 'sox foo2.wav -n stat 2>&1' had status 2

If I try to put the exact location of the file like this:

spam = system("sox C:\Program Files (x86)\sox-14-4-2\foo2.wav -n stat 2>&1", intern = TRUE)

...then the error is:

Error: '\P' is an unrecognized escape in character string starting ""sox C:\P"

...I tried to double quote the strings but to no avail. The code spam = system("sox "C:\Program Files (x86)\sox-14-4-2\foo2.wav" -n stat 2>&1", intern = TRUE) ended up with the following error:

Error: unexpected symbol in "spam = system("sox "C"

I even tried:

spam = system("sox file.path("C:", "Program Files (x86)", "sox-14-4-2", "foo2.wav") -n stat 2>&1", intern = TRUE)

To no avail...

I can confirm I have sox working correctly through the Windows command line. Can anyone help me to understand?

Thanks in advance!

Community
  • 1
  • 1
user3535074
  • 1,268
  • 8
  • 26
  • 48
  • Seems windows specific...maybe have a look at the answers to this question: http://stackoverflow.com/questions/18603984/using-system-with-windows Especially the `shell`command. – Stephen Henderson Feb 16 '16 at 21:59

1 Answers1

0

You need to escape the "\". Try something like this "C:\Program Files...".

Yuan Tang
  • 696
  • 4
  • 15
  • I'm not sure I understand your suggestion. Could you elaborate please? I don't see you escaping anything which I haven't tried in "C:\Program Files...". – user3535074 Feb 16 '16 at 21:22
  • 1
    > spam = system("sox C:\\Users\\danie\\Desktop\\Audio\\foo2.wav -n stat 2>&1", intern = TRUE) Warning message: running command 'sox C:\Users\danie\Desktop\Audio\foo2.wav -n stat 2>&1' had status 2 – user3535074 Feb 16 '16 at 21:27
  • `spam = system("sox foo2.wav -n stat 2>&1", intern = TRUE)` is the same as `spam = system("sox C:\\Users\\danie\\Desktop\\Audio\\foo2.wav -n stat 2>&1", intern = TRUE)` since you want to escapte the "\" in a string. Regarding the status 2, that's something related to Windows. You'll probably want to use `shell` instead of `system`. Hope this helps. – Yuan Tang Feb 17 '16 at 05:24