delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/02/02/08:59:57

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: "Robbie Hatley" <loneXwolfintj AT pacXbell DOT net DOT remove DOT Xs>
Newsgroups: comp.os.msdos.djgpp
References: <4017ddaa$1_6 AT Newsfeeds DOT com> <401875b6 DOT 1196777 AT news DOT voyager DOT net>
Subject: Re: How do I feed output of DOS commands into a program?
Date: Mon, 2 Feb 2004 05:05:23 -0800
Lines: 48
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <401e4acd$1_2@127.0.0.1>
X-Authenticated-User: $$-gw9vryh-3ijz759
X-Comments: This message was posted through <A href
X-Comments2: IMPORTANT: Newsfeed.com does not condone,
X-Report: Please report illegal or inappropriate use to
Organization: Newsfeeds.com http://www.newsfeeds.com 100,000+ UNCENSORED Newsgroups.
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Chris Giese" <NoEmailAds AT execpc DOT com> wrote in message news:401875b6 DOT 1196777 AT news DOT voyager DOT net...
> "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; }

That's very interesting, but doesn't really constitute "not using
temporary files".  However, I do thank you for your answer, because
it lead to me reading the documentation for the popen() and pclose()
functions, which I had never heard of before.  I read a comment in
there to the effect that "temporary files must be used because
DOS is not a multitasking operating system".  Ie, what I was
trying to do is apparently impossible.

So, I re-wrote my program so that it no-longer needs to determine
current directory through use of system("CD > tempfile.tmp") ;
instead, I test for success or failure of changing current directory:

ErrorFlag = chdir(TargetDir.c_str());  // TargetDir is a std::string
if (ErrorFlag)
{
    cerr << "oops" << endl;
    exit (1);
}

That way I can navigate directory trees recursively without using
any temporary files (either explicit or implicit, judging by lack of
activity of IDE LED), and still have error-checking on whether
current-directory-changes were successful.  (This is program
that seeks-out and erases duplicate files.)

RH




----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---

- Raw text -


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