469,128 Members | 1,661 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,128 developers. It's quick & easy.

run a shell command with C code in OS X

hi,
I'm a first year student at UNSW Sydney, i was wondering if somebody
could tell me how to run a terminal command from within OS X. A easy
to understand example of why i would want this is:
1. Running winRAR or some other compression program to decompress a
file within the working directory.
2. Running growlnotify to give user feedback rather then through the
command line.
3. running the say command to get the computer to say something
4. running screencapture

i would be extremely greatfull if anyone out there can be of some
assistance.

thanks in advanced!

Jul 28 '07 #1
6 3503
sushi boi wrote:
hi,
I'm a first year student at UNSW Sydney, i was wondering if somebody
could tell me how to run a terminal command from within OS X.
And why are shell commands in OS X topical in a Standard C group? Post to a
system specific group like <news:alt.comp.os.macor at least
<news:comp.programming>

<snip>

Jul 28 '07 #2
On Jul 28, 1:32 pm, sushi boi <sushant...@gmail.comwrote:
hi,
I'm a first year student at UNSW Sydney, i was wondering if somebody
could tell me how to run a terminal command from within OS X. A easy
to understand example of why i would want this is:
1. Running winRAR or some other compression program to decompress a
file within the working directory.
2. Running growlnotify to give user feedback rather then through the
command line.
3. running the say command to get the computer to say something
4. running screencapture

i would be extremely greatfull if anyone out there can be of some
assistance.

thanks in advanced!
Very off-topic, but go to developer.apple.com and go from there.

Jul 28 '07 #3
sushi boi <su********@gmail.comwrote:
# hi,
# I'm a first year student at UNSW Sydney, i was wondering if somebody
# could tell me how to run a terminal command from within OS X. A easy
# to understand example of why i would want this is:

If your system supports the system() function, just call
int rc = system("shell command in some string expression");

It will run the command with a shell (or as if with a shell), but
the implementation is system specific.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
TEMPORARILY CLOSED
BE OPENED AFTER FIRST PERIOD
Jul 28 '07 #4
santosh <sa*********@gmail.comwrites:
sushi boi wrote:
>I'm a first year student at UNSW Sydney, i was wondering if somebody
could tell me how to run a terminal command from within OS X.

And why are shell commands in OS X topical in a Standard C group? Post to a
system specific group like <news:alt.comp.os.macor at least
<news:comp.programming>
The question is actually quite topical if you ignore the irrelevant
OS X aspect of it. The answer is the system() function.

(There may well be other approaches that are specific to OS X; those
approaches would be off-topic.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 28 '07 #5
sorry for being off topic..i'll go to those other pages next time..
i came here because its the C programming forum... and i thaught i
needed a C fn to do what i needed it to do.. not a OS-X specific Fn

Jul 30 '07 #6
sushi boi <su********@gmail.comwrote:
# sorry for being off topic..i'll go to those other pages next time..
# i came here because its the C programming forum... and i thaught i
# needed a C fn to do what i needed it to do.. not a OS-X specific Fn

The system() function is ANSI C and thus on topic by any conceivable
definition of on-topic. However how it is implemented is system
specific.

On any Unix, the string will be given to shell in a child process
for the shell to deal with; the system() function waits for child
exit and returns exit code. Any files have to be in the shell
command string.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
So....that would make Bethany part black?
Jul 30 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Siemel Naran | last post: by
6 posts views Thread by Lauren Wilson | last post: by
8 posts views Thread by zhiwei wang | last post: by
4 posts views Thread by Anastasios Hatzis | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.