Mailing Lists: Apple Mailing Lists

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

popen with r+



So I was very sad to learn that popen with r+ doesn't work on jaguar
and panther, at least without the latest OS Updates. Is there any
other API that I can use to accomplish launching a process and then
reading from its stdout and writing to its stdin that works on both
Jaguar and Panther using non NSTask stuff.

I tried looking at popen's source and doing the pipes and forks like
it does it but fdopen keeps returning EINVAL (22) not liking the "r+"
mode I send it. Here is my ldpopen method:

i call it using ldpopen(command, "r+");

static int pid = -1;

static FILE * ldpopen(const char *command, const char *type)
{
	char *argv[4];
	int pdes[2];
	FILE *iop;
	
	if (pipe(pdes) < 0)
		return (NULL);
	
	argv[0] = "sh";
	argv[1] = "-c";
	argv[2] = (char *)command;
	argv[3] = NULL;
	
	switch (pid = vfork())
	{
		case -1:
			close(pdes[0]);
			close(pdes[1]);
			return NULL;
		case 0:
			close(pdes[0]);
			if (pdes[1] != STDOUT_FILENO) {

				(void)dup2(pdes[1], STDOUT_FILENO);
				(void)close(pdes[1]);
				errno = 0;
				int prob = dup2(STDOUT_FILENO, STDIN_FILENO);
				int y = errno;
				y = prob;
			}
			else if (pdes[1] != STDIN_FILENO)
			{
				(void)dup2(pdes[1], STDIN_FILENO);
			}
			execv(_PATH_BSHELL, argv);
			exit(127);
	}

	if (*type == 'r') {
		iop = fdopen(pdes[0], type);     // this returns null with errno being 22
		(void)close(pdes[1]);
	} else {
		iop = fdopen(pdes[1], type);
		(void)close(pdes[0]);
	}
	return iop;
}


Any help would be greatly appreciated, thanks. Matt _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to 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.