PDA

View Full Version : java: trying to access terminal, trying to make an alias




zredbaron
Apr 9, 2008, 09:59 PM
does anyone know how i can create an alias programattically from java?

i've done google searches and found commands to type into a terminal, but they are limited in that they dont seem to allow an icon file.

to complicate things, i don't believe Runtime.getRuntime().exec(String[] args); handles commands like the terminal does.

is there a way to enter commands into a terminal from java?

thanks in advance.



lee1210
Apr 9, 2008, 10:08 PM
If trying to invoke the commands directly isn't working, you might want to make a very short shell script that does this, and invoke that from your program.

-Lee

zredbaron
Apr 9, 2008, 10:23 PM
ah, that sounds like a very good idea!

but how exactly would i go about calling a shell script from java? i tried asking google, but i dont seem to be typing in the right search string....

lee1210
Apr 9, 2008, 11:13 PM
catch-22, I suppose. You're back to using exec. It should be ok if the script is in your path. A much messier way is to use JNI to get into C/C++, but that is the road to madness.

Are you using java to do some system scripting? Or is this the OS X installer of a larger Java app? If you're just trying to automate things, java may not be the way to go.

-Lee

zredbaron
Apr 10, 2008, 09:21 AM
found a solution for the script part:

String[] test = {"sh", ".script.sh"};
runtime.exec(test);

thanks a lot for the idea.

i think ill post the bit about the alias in a new thread. thanks again.

jeremy.king
Apr 10, 2008, 09:39 AM
Since you are simply calling a script from Java, you may want to consider calling an Applescript instead.

Your input arguments to exec() would be
String[] test = {"osascript", "YourAppleScript.scpt"};