Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

running a terminal command in xcode

Hey guy and gals

I had a question for the xcode experts out there. I'm new to using xcode and to objective c. The problem I'm having is I'm trying to tell my program to run a code that terminal uses. Of course xcode throws back errors. How do I tell xcode to run the terminal syntax code so that I can get this program running?

Thanks
James

Mac OS X (10.5.8)

Posted on Aug 23, 2009 1:59 PM

Reply
6 replies

Aug 23, 2009 2:42 PM in response to drklost

From elsewhere on the 'net...


Launch Terminal application and type:
man gcc
man make
if you can compile and link your app to a runnable binary then type:
cd todirectory_of_yourprogram
./nameof_myprogram
and your program will respond to stdin and stdout, the two standard input and output streams for unix.
So, you type input which goes to your program using stdin (fscanf(stdin, format, &args)) and issue output to stdout (fprintf(stdout, format, args...) )
If you want, make new Terminal windows and repeat to run multiple copies of your app one one computer.
or use ./nameof_myprogram < input_file &
(or something similar).

Aug 23, 2009 3:59 PM in response to xnav

I started with a Cocoa App. Let me try and explain what I'm trying to do. It might shed some light on my problem. I'm trying to write a program that runs this code with a click of a button.

defaults write com.apple.finder AppleShowAllFiles TRUE

killall Finder

normally I open up a terminal and run the code. Works great. Well my wife is in the hospital with preeclampsia and I'm not leaving her side. since she is here till our son is born or if she can make it to 34 weeks so the doctors can induce. shes at 31 weeks 4 days.

anyways I decided to give myself something to do while we sit around all day. shes not aloud tv do to the risk of seizures. So i thought to myself why don't i try to write a program that when i click the button it will run the code automatically and then when im done reverse it. Since i dont want my hidden files shown all the time. So I'm trying to tell xcode to run this code in the background and display hidden files then when I click hide hide the hidden files.

Aug 23, 2009 4:19 PM in response to drklost

Use Applications>Utilities>AppleScriptEditor and build a script with the two commands in it using the doc [here|http://developer.apple.com/technotes/tn2002/tn2065.html]. Then use 'Save As' and save the script as an application to your desktop. Double clicking the script on the desktop should give the results you want. Xcode is not necessary.

Aug 24, 2009 8:20 AM in response to drklost

Just to run the shell commands:
Xcode>File>NewProject>CommandLineUtility>FoundationTool then use NSTask as [here|http://www.insanelymac.com/forum/lofiversion/index.php/t114129.html]. However, I think if you search the doc you can find classes that will perform the same functions as the shell commands.

running a terminal command in xcode

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.