Calling a command line program in Objective-C

Discussion in 'Web Design and Development (archive)' started by smknappy, Jan 29, 2004.

  1. smknappy macrumors member

    Nov 21, 2003
    Hi all,

    I'm new to Mac dev and was wondering if there is an easy way to execute a command line program from an objective-c app.

  2. Rincewind42 macrumors 6502a


    Mar 3, 2003
    Orlando, FL
    Re: Calling a command line program in Objective-C

    To start you may want to join some number of Mac developer lists . And second to actually do this is something like this:

    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/wait.h>
    #include <unistd.h>

    int main()
    pid_t pid = fork();
    if(pid != 0)
    // parent
    waitpid(pid, &status, 0);
    // child
    execlp("grep", "grep", "foo", NULL);

    return 0;

    This will only run the command line tool, any output it makes will still be directed elsewhere, so if you need that you will need to dig a bit deeper.
  3. FattyMembrane macrumors 6502a


    Apr 14, 2002
    bat country
    if you search apple's developer connection, you can find a cocoa wrapper for the "mpg123" utility that will allow you to make a quick and easy mp3 player by calling the command line utility. you can just lift the code right from that example.

    p.s. i think this is in the wrong section;)

Share This Page