X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: "Nathan Kreiger" Newsgroups: comp.os.msdos.djgpp Subject: How do I feed output of DOS commands into a program? Date: Wed, 28 Jan 2004 08:06:18 -0800 Lines: 55 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: <4017ddaa$1_6@Newsfeeds.com> X-Authenticated-User: $$-gw9vryh-3ijz759 X-Comments: This message was posted through 2 Newsfeed.com X-Comments2: IMPORTANT: Newsfeed.com does not condone, support, nor tolerate spam or any illegal or copyrighted postings. X-Report: Please report illegal or inappropriate use to . Forward a copy of ALL headers INCLUDING the X-Comments3: Visit Newsgroups.com for the BEST newsgroup service on the planet!! Organization: Newsfeed.com - #1 Newsgroups service on the planet! - http://www.Newsfeed.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com 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: system("cd > C:\\TEMP\\curdir.tmp"); ifstream input ("C:\\TEMP\\curdir.tmp"); etc..... However, when processing a large number of directories this becomes impractical (and very hard on the hard disk, what with repeatedly writing to the exact same spot on the disk thousands of times within a few seconds). (Yes, I'm aware of getcwd() and getwd(), but I don't like the fact that they tend to mix DOS and LFN versions of directory names together in an unpredictable way; that makes them useless for my purposes. Besides, I'd still like to find a way to pass DOS command results into C++ programs.) I tried seting an environmental variable in one program and reading it in another: PROG1.cpp: int main(int argc, char *argv[]) { __system_flags |= __system_call_cmdproc; __system_flags &= ~__system_redirect; char command[300] = "set RH_ENV_VAR="; strcat(command, argv[1]); system(command); return 0; } PROG2.cpp: int main() { __system_flags |= __system_call_cmdproc; __system_flags &= ~__system_redirect; cout << getenv("RH_ENV_VAR") << endl; return 0; } I ran PROG1 and set the variable to "One, two, three, test.", but when PROG2 trys to read the variable, it's already gone. (Garbage collection at work?) Is there a way to set environmental variables so that they stay put even when the program that set them terminates? -- Cheers, Robbie Hatley Tustin, CA, USA lonewolfintj AT pacbell DOT net http://home.pacbell.net/earnur/ ----== 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 =---