run a shell command with C code in OS X

S

sushi boi

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!
 
S

santosh

sushi said:
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 <or at least
<
<snip>
 
C

christian.bau

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.
 
S

SM Ryan

# 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.
 
K

Keith Thompson

santosh said:
And why are shell commands in OS X topical in a Standard C group? Post to a
system specific group like <or 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.)
 
S

sushi boi

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
 
S

SM Ryan

# 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,150
Messages
2,570,853
Members
47,393
Latest member
silloma

Latest Threads

Top