Welcome to MacTalk Australia

the largest Australian community for Apple discussions and topics

Join the discussions, Register Now!
Results 1 to 6 of 6
  1. #1

    Join Date
    Jan 2004
    Location
    New Hampshire, US
    Posts
    1,492

    Default Invoking a single command in Terminal

    When using an xterm on most Unix systems (including OSX) my project's needs are met by invoking xterm -e myprogram its_arguments - a new X terminal window opens, myprogram is invoked "within" it, and the new xterm manages the ASCII I/O. I can further use xterm's -hold command-line option to keep the window open after myprogram terminates. This all works well under OSX, but it does require the X11 server to be running.

    Is there any equivalent for Apple's native Terminal program? Can I invoke Terminal and provide a "one-off" command to execute within it?

    And, if so, how did you find such information - without a standard online manual for Terminal, Terminal appearing to accept no command-line options, and Apple's Help on Terminal providing little, I'm lost! Thanks,
    It's better to burn out than it is to rust.

  2. #2

    Join Date
    Jan 2004
    Location
    Sydney
    Posts
    5,960

    Default

    I am guessing you could use an AppleScript procedure to open terminal, execute a command.. and keep it open? Although I do not know AppleScript myself, so cannot provide an example.

  3. #3

    Join Date
    Jan 2004
    Location
    New Hampshire, US
    Posts
    1,492

    Default

    Quote Originally Posted by purana View Post
    I am guessing you could use an AppleScript procedure to open terminal, execute a command.. and keep it open? Although I do not know AppleScript myself, so cannot provide an example.
    Thanks, but all of this happens from within a C program - currently the xterm is invoked using execve(....)

    If AppleScript offers some assistance (I don't wish to use it because I may as well just keep running the X11 server!) I'd like to learn how AppleScript does it, and then I can mimic that from my C code.
    It's better to burn out than it is to rust.

  4. #4

    Join Date
    Jan 2004
    Location
    Sydney
    Posts
    5,960

    Default

    Quote Originally Posted by chrism238 View Post
    Thanks, but all of this happens from within a C program - currently the xterm is invoked using execve(....)
    Oh really, guess you never mentioned that. In that case I think your stuck using an xterm

  5. #5

    Join Date
    Feb 2007
    Location
    Toongabbie, NSW
    Posts
    3,070

    Default

    From the command line you can invoke Terminal with an argument being a text file containg shell comands. Hence, if you put

    Code:
    /bin/ls -la
    into a file called command you can run it in a Terminal window like this:

    Code:
    $ /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal ~/command
    (for some reason Terminal wants an absolute path for the command file).

    You should be able to do the same from within C.

    Cheers
    Steffen.
    It's Unix, Jim, but not as we know it...

  6. #6

    Join Date
    Jan 2004
    Location
    New Hampshire, US
    Posts
    1,492

    Default

    Quote Originally Posted by dotnet View Post
    From the command line you can invoke Terminal with an argument being a text file containg shell comands. Hence, if you put
    Code:
    /bin/ls -la
    into a file called command you can run it in a Terminal window like this:
    Code:
    $ /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal ~/command
    (for some reason Terminal wants an absolute path for the command file).

    You should be able to do the same from within C.
    Thanks Steffen, yes, I had tried these basics but try anything "complex" like appending /bin/ls -l or "/bin/ls -l" or "/bin/sh -c '/bin/ls -l'" and watch Terminal randomly fail to launch, get stuck in the Dock, or cause a need for a reboot (don't try some of these at home!)
    Basic Unix stuff, but far from as slick as most other Apple software.
    Gotta go, time to reboot again.....
    It's better to burn out than it is to rust.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •