Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 9, 2008, 09:59 PM   #1
zredbaron
macrumors newbie
 
Join Date: Apr 2008
java: trying to access terminal, trying to make an alias

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.
zredbaron is offline   0 Reply With Quote
Old Apr 9, 2008, 10:08 PM   #2
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
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
lee1210 is offline   0 Reply With Quote
Old Apr 9, 2008, 10:23 PM   #3
zredbaron
Thread Starter
macrumors newbie
 
Join Date: Apr 2008
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....
zredbaron is offline   0 Reply With Quote
Old Apr 9, 2008, 11:13 PM   #4
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
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
lee1210 is offline   0 Reply With Quote
Old Apr 10, 2008, 09:21 AM   #5
zredbaron
Thread Starter
macrumors newbie
 
Join Date: Apr 2008
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.

Last edited by zredbaron; Apr 10, 2008 at 09:31 AM.
zredbaron is offline   0 Reply With Quote
Old Apr 10, 2008, 09:39 AM   #6
jeremy.king
macrumors 603
 
jeremy.king's Avatar
 
Join Date: Jul 2002
Location: Fox Lake, IL
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"};
jeremy.king is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Using Terminal to write programs, not allowing me to access the university's servers? smokeybear Mac Programming 4 Feb 2, 2013 12:32 AM
with no user pass, can't access terminal scottroberts Mac OS X 10.7 Lion 5 Dec 1, 2012 08:33 PM
THIS IS DANGEROUS, root access inside a Terminal. wisecracker MacBook Pro 9 Nov 1, 2012 05:59 PM
Access external hard drive attached to airport from terminal mr sbe OS X 1 Sep 28, 2012 02:27 AM
Make missing from terminal? intervenient Mac Basics and Help 1 Aug 25, 2012 12:04 AM

Forum Jump

All times are GMT -5. The time now is 03:25 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC