1

I am aware that you can pass commands to the Terminal and it returns your result in Java. The problem is for undisclosed reasons I need a Terminal window to open and to have the command in it. This code works to open an empty Terminal window (on mac):

p = Runtime.getRuntime().exec("/usr/bin/open -a Terminal");

And I have seen someone say on a different overflow question that you can do this:

p = Runtime.getRuntime().exec("/usr/bin/open -a Terminal [Put Command to pass through here]");

But it didn't seem to work when I tried to pass the command through to the window.

Any help or suggestions?

Rob S
  • 13
  • 4
  • Are you working on osx ? – Fr0z3n7 May 30 '14 at 14:01
  • See this question and answer: https://stackoverflow.com/questions/21496182/mac-os-x-passing-pathname-with-spaces-as-arguments-to-bashscript-and-then-issu –  May 30 '14 at 17:43

1 Answers1

0

You can achieve this by using AppleScript.

Here you can find example how call it from Java: AppleScript from Java on Mac OS X 10.6?

And script you need will look like this:

tell application "Terminal"
    set currentTab to do script ("cd ~/Downloads/")
    set currentTab to do script ("ll")
end tell
Community
  • 1
  • 1
Al Zonke
  • 532
  • 6
  • 8