0

Possible Duplicate:
Java execute a command with a space in the pathname

I am having following command

i_view32.exe C:\*.bmp /import_pal=C:\default.pal /convert=D:\temp\*.bmp Which when i run through command prompt works fine. I am trying to run the same command with the help of java.

 Process p = Runtime.getRuntime().exec(System.getenv("ProgramFiles")+"\\IrfanView\\i_view32.exe  c:\\*.bmp /import_pal= 1.pal /convert=d:\\temp\\*.bmp");

But i am not able to get Output in d:\\temp\\ Folder. Can any one suggest me where i am wrong.

Thanks in Advance..

Is there any other way to give "/" as i am using slash /import_pal=

Community
  • 1
  • 1
Code Hungry
  • 3,930
  • 22
  • 67
  • 95
  • did you check if `System.getenv("ProgramFiles")` actually returns what you need ? – Simeon Nov 08 '11 at 08:22
  • 1
    have you tried using the exec with String[] parameter? Im quite sure using Process.exec(String command) doesnt work if you have additional params. – Henrik Nov 08 '11 at 08:27
  • does the command gives some output.. you can try reading with p.getInputStream() and p.getErrorStream() to get the outputs from the process – Ash Nov 08 '11 at 08:28
  • 1
    I have found this one quite useful for executing some complex commands through java.. http://www.devdaily.com/java/java-exec-processbuilder-process-1 – Ash Nov 08 '11 at 08:29
  • Try using: ProcessBuilder builder = new ProcessBuilder(String[] commands).start(); – d1e Nov 08 '11 at 08:52

2 Answers2

0

Try to execute CMD

Example:

proc = Runtime.getRuntime().exec("cmd.exe /c dir");

It should work something like this, for your example it's a bit more complicated, but try it this way.

MOleYArd
  • 1,258
  • 1
  • 12
  • 16
0

2 your attempts are not exactly the same. I think that you executed command from command prompt when you were in c:\Program Files\IrfanView. When you are trying to run the same command from java you mention the full path. Since some programs are sensitive to current working directory I'd recommend you first to try to run the command from other directory (e.g. from c:) but specify full path.

If it works manually but does not work from java try to use ProcessBuilder instead of Runtime.exec(). Actually it is almost the same but it more Object Oriented and allows to specify working directory separately. I hope this will work for you.

If not try to play with quotes. Directory path 'c:\Program Files' contains space, so the path should be quoted.

Good luck.

AlexR
  • 114,158
  • 16
  • 130
  • 208