0

I am trying to convert various xls files into csv. when I execute the following command in the terminal it works fine

    libreoffice --headless --convert-to csv --outdir 
/Data/edennis/ /Data/edennis/2013-10/*.xls

but when I try with runtime exec it does not.

Research I've done:

  1. According to this thread Java Runtime exec() behavior cannot execute system commands like echo, but libreoffice is not a system command, isn't it an executable program ?
  2. Java runtime execThis thread recommends to use processBuilder, but not sure if this is what I would need to do in my case.
  3. According to the Java Doc:

EXEC: Executes the specified string command in a separate process with the specified environment.

3
  • Is there any error you'd like to share with us? Commented Nov 25, 2013 at 14:41
  • How do you call it? Perhaps you have to give full path to the executable file? Commented Nov 25, 2013 at 14:41
  • @piet.t no error, it doesnt break it runs through but it doesnt execute.. Commented Nov 25, 2013 at 14:43

1 Answer 1

3

First, there is no reason why Runtime.exec should not be able to run /bin/echo (if available).

Second, yes, use ProcessBuilder.

Third, your problems stem from using shell syntax for file patterns like *.xls. Runtime.exec calls the program you specify, not a shell that would do filename expansion. If you need to do filename expansion, run a shell like:

"sh -c libreoffice --blabla *.xls"
Sign up to request clarification or add additional context in comments.

1 Comment

it worked thanks! I had to use a String array but otherwise worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.