• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about external command binaries and file paths  RSS feed

 
Ken Whitestone
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a shell script that I wrote a while back and I want to try and use what I've learned in Java to translate it into a Java application. The shell script relied in some part on an open source binary that I included with the script. The script would just use relative file paths to point to the binary and all was well. However, I'm having some trouble doing the same thing in Java. I know I can use the following code to execute an external command from within the Java application:



The problem with that is, it seems to require the full path to the command (binary) being used. Every time I try to use a relative file path (./<command>), the program throws and exception and says the file can't be found, even though there is a copy in both the "bin" and "src" directories of that project. Is it possible for me to use a relative file path so I can package the binary with the Java application and still have it work on any compatible system?

[Edit:] I'm using Eclipse, if that matters.
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have the control over which working directory eclipse runs the program from?
 
Ken Whitestone
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I assumed (silly me) that since the Java application was being executed from the "src" directory, then any binaries in that directory would be in it's relative path. Clearly, I was mistaken as I specifically had to define the working directory in Eclipse by going to the run configurations, selecting the arguments tab, and choosing "other" to select the correct directory. Looking back, I could have just edited the command to be relative to what was actually the current working directory instead of "src" (I think I'll do that anyway).

Thanks for your help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!