delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/01/28/22:45:48

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: NoEmailAds AT execpc DOT com (Chris Giese)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: How do I feed output of DOS commands into a program?
Date: Thu, 29 Jan 2004 02:58:18 GMT
Organization: PROPULSION GROUP
Message-ID: <401875b6.1196777@news.voyager.net>
References: <4017ddaa$1_6 AT Newsfeeds DOT com>
X-Newsreader: Forte Free Agent 1.21/32.243
X-Complaints-To: abuse AT supernews DOT com
Lines: 18
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Nathan Kreiger" <nathankreiger AT hotmail DOT com> wrote:

>Greetings, group.  I'm writing a program in C++ and compiling with
>DJGPP's gxx, and I'd like to be able to run DOS commands such
>as "CD" (get current directory) and funnel the result back into my
>program, without using temporary files.  I could always do:

Use popen() and pclose():

#include <stdio.h>
int main(void) {
	static char buf[8000];
	FILE *pipe = popen("CD", "r");
	(void)fread(buf, 1, sizeof(buf), pipe);
	pclose(pipe);
	printf("%s", buf);
	return 0; }

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019