开发者

exec, files location problem

In my jar application I do some calculations in exe program. When files and program.exe was in the same dir I used this command:

String[] str={"program.exe", "file1.txt", "file2.txt"};
pr = rt.exec(str);

and it worked great. But when I moved files to other dir and I try use this command:

String[] str={"program.exe", "temp\\file1.txt", "temp\\file2.txt"};
pr = rt.exec(str);

program.exe doesn't see files. What is more odd it start to see files when I change its names for anything else that default. file1.txt, file2.txt and temp are created in my jar program before program.exe start.

edit:

When problem started I try sth like this: default names file1.txt and file2.txt, I changed to aaa.txt and bbb.txt (in windows), 开发者_开发技巧and then:

 String[] str={"program.exe", "temp\\aaa.txt", "temp\\bbb.txt"};

and it works.

edit2:

Now I know that problem is in program.exe. When I use it from command line (not from jar), like this:

program.exe temp\file1.txt temp\file2.txt 

error:

FANN Error 1: Unable to open configuration file "temp\file1.txtÉ║@" for reading.

fann is artificial neural network library. When I copy files to program.exe dir:

program.exe file1.txt file2.txt 

it works! When I changed files names in temp and do:

program.exe temp\file1aaa.txt temp\file2bbb.txt

it works also! So it is fann lib bug?


I'd use the ProcessBuilder api (it gives you much more control than Runtime.exec()) and I'd also use absolute paths:

File directory = new File("/path/tp/program.exe's/parent");

int returnCode = new ProcessBuilder("program.exe", 
    new File(directory, "temp/file1.txt").getAbsolutePath(),
    new File(directory, "temp/file2.txt").getAbsolutePath()
)
.directory(directory).start().waitFor();


Give complete path of the filename and see. Something like below

String[] str = {"program.exe", "D:\\temp\\file1.txt", "D:\\temp\\file2.txt"}; 

If your OS is UNIX based then change it accordingly.


Have you tried relative path for finding the location like
abc (folder)
 -> code(folder)
  -->Program.Java
 -> temp
  --> file1.txt
so
when u run ur program in Eclipse IDE
ur relative path will be from program.java file is
../temp/file1.txt And try to use / instead of \ so that it wont take as an escape character.
when u run from a jar You need to extract the temp folder from jar to outside
abc (folder)
 -> jar (folder)
  -->Program.jar
 -> temp
  --> file1.txt

OR
Read the jar content from the program as a zip file. Reach your temp folder inside it by code and then read the content as input stream.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜