aspose file tools*
The moose likes Java in General and the fly likes How to call/control .exe file not in current directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to call/control .exe file not in current directory" Watch "How to call/control .exe file not in current directory" New topic
Author

How to call/control .exe file not in current directory

Tony Tranquil
Greenhorn

Joined: Sep 23, 2003
Posts: 24
I got a problem when I use a class file to call an .exe file which is not in the current folder the class is in. For example, a A.exe file is in such folder like below. A.exe uses some imgaes files using relative path. And caller.class in other foler.
c:\
|----app
| |
| |----A.exe
| |
| |----images
| |
| |----images.jpg
|
|----javaapps
| |
| |-----caller.class
When I run caller.class file in javaapps folder, I got error message which told me A.exe file can not find image file. If put A.exe and images folder with image file in javaapps folder, caller.class works fine.
Could anybody please tell what's wrong, how to solve this problem?
Thanks
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
Hi Tony
Try to write a batch file (as you seem to be on Windows) that runs A.exe. In the batch file you write the following,
test.bat
---------
cd c:\app
A.exe
and see if it works...
The problem here is from Java we can't "cd" directory you know and if we execute the way you are trying (from javapps folder via the class file) then it wouldn't find "images" as in A.exe images are referred relatively (to apps folder)...
See if it works..
Regards
Maulin
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
Btw, forgot to mention that we should try running this batch file from the java code instead of the A.exe directly....we can put this batch anywhere as far as our java code writes correct path to it...
Regards
Maulin
Tony Tranquil
Greenhorn

Joined: Sep 23, 2003
Posts: 24
Hi Maulin,
First, Thank you for your reply. Following your suggestion, the program still doesnt work well, the Caller class got return value 1, but A.exe can not run. I post my source code below, please help me have a look.
Thanks alot.
Tony
public class Caller {
public static void main(String[] args) {
try{

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("C:\\app\\go.bat");
int exitVal = proc.waitFor();
System.out.println("Process exit value: " + exitVal);
}catch(Throwable t){
System.out.println(t.getMessage());
}
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to call/control .exe file not in current directory