Forums Register Login

Start exec in current directory from Java

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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():
+Pie Number of slices to send: Send
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?
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1765 times.
Similar Threads
directory
run time error No class def found error
using zip in process
Reading external files from a jar
Unable to Get Maven Installed
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:06:41.