• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
popen with r+
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

popen with r+


  • Subject: popen with r+
  • From: "matt jaffa" <email@hidden>
  • Date: Tue, 20 Jun 2006 17:03:12 -0600

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: This email sent to email@hidden
  • Follow-Ups:
    • Re: popen with r+
      • From: Ian Lister <email@hidden>
  • Prev by Date: Re: Apple Libtool
  • Next by Date: Re: popen with r+
  • Previous by thread: Re: dyld sources vs dyld binaries
  • Next by thread: Re: popen with r+
  • Index(es):
    • Date
    • Thread