Re: call C application
Re: call C application
Mai Bui wrote:
Can a cocoa application call another application written in C?
For instance, I have a cocoa application with the "RUN" and "STOP"
button.
I would like to implement:
- when the user press "RUN" button, it will run another my application
(written in C).
- and press "STOP" button, it send 'q' character to the running
application to stop that application and then quit its self (the cocoa
application).
Is it possible to do that?
Thanks for any idea and help.
Way 1 (Cocoa way):
Please read documentation for NSTask class. Use NSTask as wrapper.
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSTask.html
Way 2 (UNIX way):
If you don't want to hook input/output streams (STDIN/STDOUT) then you
can simple call C-library function
system();
from man:
NAME
system -- pass a command to the shell
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stdlib.h>
int
system(const char *string);
DESCRIPTION
The system() function hands the argument string to the command inter-
preter sh(1). The calling process waits for the shell to finish
execut-
ing the command, ignoring SIGINT and SIGQUIT, and blocking SIGCHLD.
If string is a NULL pointer, system() will return non-zero if the
command
interpreter sh(1) is available, and zero if it is not.
The system() function returns the exit status of the shell as
returned by
waitpid(2), or -1 if an error occurred when invoking fork(2) or
waitpid(2). A return value of 127 means the execution of the shell
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden