java: trying to access terminal, trying to make an alias

Discussion in 'Mac Programming' started by zredbaron, Apr 9, 2008.

  1. macrumors newbie

    Joined:
    Apr 9, 2008
    #1
    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.
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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
     
  3. thread starter macrumors newbie

    Joined:
    Apr 9, 2008
    #3
    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....
     
  4. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    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
     
  5. thread starter macrumors newbie

    Joined:
    Apr 9, 2008
    #5
    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.
     
  6. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #6
    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
    Code:
    String[] test = {"osascript", "YourAppleScript.scpt"};
     

Share This Page