Eddie Martinez
Eddie Martinez

Reputation: 13910

Java runtime exec

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.

Upvotes: 0

Views: 429

Answers (1)

Ingo
Ingo

Reputation: 36339

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"

Upvotes: 3

Related Questions