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



Stantard OS techniques:

1) Create a pipe for stdin and another one for stdout (man pipe) [that's four file descriptor total]
2) Fork your process (man fork)
3) In the child process, close 0 & 1 and use dup (man dup/dup2) to rebind the read/write end of the pipes to 0/1 (stdin/stdout) descriptors.
4) Use an exec system call to load a new program into the child's process address space. That child will use as stdin/stdout what you did setup in 3. (man execl / execlp /execvp /.....)
5) Don't forget to reap the child process from the parent (man wait) when you're done.
6) communicate with the child through the pipes.


Hope it helps,

PS/ The pipes will go away once _all_ its file descriptors are closed. So dont' forget to close the ends that you do not use right away (e.g., the write-end of the pipe used for stdout in the parent... you'll only read from that one)

On Dec 21, 2005, at 3:08 PM, 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/ldm% 40thorgal.homelinux.org


This email sent to email@hidden

-- Laurent


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