Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 will open the floodgates of his own worst nightmare! All in a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic