Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: programatic tool interaction



You need to fork off a new process then exec the tool from the child. The child process does not return. You can open pipes prior to the fork, since the parent and child process share file descriptors.

Something like this:

    int socks[2];

    /* open socket pair */
    int retval = pipe(socks);
    if (retval < 0)
      perror("opening socket pair");

    /* fork off a child process */
    pid_t pid = fork();
    if (pid == -1)
      perror("Failed to fork\n");

    if (pid == 0) {
      /* child process */
      close(socks[1]);
      dup2(socks[1], 2);
      close(socks[0]);

      execl(cmd, cmd, arg1, arg2, 0);
      // exec only returns on failure
      perror("Didnt exec.");
      exit(EXIT_FAILURE);
    }

I hope this is clear, I've just woken so my brain's a bit mushy. The man pages are your friend, but if you need further info, dont hesitate to ask.



On 22/12/2005, at 9:08 AM, Kevin Packard wrote:

Please forgive me if this is not the appropriate list, but I've not been unable to google the answer, or find it in Apple's dev pages.

Is there any way to programatically interact with a UNIX tool from a Carbon app? sysctl() gives me a one-shot run, but I'd like to launch a tool, create some sort of a pipe to it, write to its stdin, and read from its stdout.

Can someone please point me to a method to do this (or tell me I'm insane)?

thanks,
--
Kevin Packard

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Unix-porting mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/unix-porting/email@hidden

This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Unix-porting mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/unix-porting/email@hidden

This email sent to email@hidden
References: 
 >programatic tool interaction (From: Kevin Packard <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.