• Post Reply Bookmark Topic Watch Topic
  • New Topic

Start exec in current directory from Java  RSS feed

 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to run a Linux program that's in my current directory from my Java program. The program is called "player".
The problem I seem to have is that this Linux program is not in the PATH.
I figured I could add "./" as a prefix, but it didn't work:
Runtime.getRuntime().exec("./player");
If I put "player" into my "bin" directory is does work, so I figure it's a PATH problem.
So, how do I add the current directory to my path?
I want to be able to distribute this program, so it won't be possible to go in an edit each users PATH manually, etc.
Thanks,
Drew
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure how to do this in Java. There must be some way to get at the OS environment.
Nevertheless, I believe that exec() somehow goes through the environment just a the shell does.
In the Shell has a feature called keyword parameters where you set a variable for just the 'current' command:

var's 'current' value (or var itself) is only available for command. Once command completes $var either has the value what before. if var was not defined, then it not available at all.
Try to apply this to exec():
 
stephen Kang
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you want to export in your shell, (i assume you use bash shell), just put your environment path to .bashrc
put these on your path environment
export JAVA_HOME=/opt/java/j2sdk_1.4.1_01 (whatever your path to java)
export PATH=$JAVA_HOME/bin:/bin/sbin... etc
so, make a variable name on your .bashrc, and export to PATH.
If you want to add your path variable to your own program, such as tomcat, strut, whatever,
make a path variable like JAVA_HOME
and export to the PATH.
./ simply means current directory you want to execute it.
besides, if you want to export globally, you want to change /etc/bashrc or /etc/profile
hope that it will help

is that what you are asking for?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!