views:

63

answers:

1

Is there such thing? I need to make an application in Xcode to basically do what the terminal app does. With just an nstextfield as the input, a label for the terminal output, and a send button. All this needs to be done without terminal accually being open.

Is this possible? If so, can someone post a website or sample code?

+2  A: 

It's certainly possible. The Terminal basically just runs a shell (bash by default). You could just launch an app that forwards entered text onto bash, and let bash do the work. Or you could interpret the input yourself. Bash is pretty simple, for the most part: you type in a program and arguments, it finds the program in the $PATH, and launches it with the given arguments. (Of course, bash gets a bit fancier, which pipes, input/output redirection, scripting, background tasks, etc., but if you don't need that in your application, you could ignore those features.) You can use NSTask, system(3), or the exec family of tasks to launch processes (probably NSTask is your best bet).

mipadi
Can all this be done without terminal being open?
Elijah W.
@Elijah Wood: Nothing mipadi said involves Terminal.app.
Chuck
Ok thanks! How do I get terminal's response? I'm using this with the charlie AI. It can be run through terminal. So I want to create a nice GUI for it. I don't think these methods will work. ADDITIONAL INFO: I have to do a ./server.sh to run the thing.
Elijah W.
You can use `NSTask` in conjunction with `NSPipe` to interact with a launched task. See http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/OperatingSystem/Tasks/pipes.html#//apple_ref/doc/uid/20000805-BAJEEBAB
mipadi
Elijah: The critical thing to understand about what mipadi is talking about is that command-line tools, including shells themselves, are not run **within** Terminal, they are run **by** Terminal. Thus you don't want to "get Terminal's response," you want to get the command line tool's response.
Chris Hanson