Subj : Re: How to execute a shell command To : borland.public.cpp.borlandcpp From : "Siemel Naran" Date : Mon Feb 02 2004 06:55 pm Jack Klein wrote: >On 1 Feb 2004 22:54:36 -0800, "Siemel Naran" >> "Ed Mulroy [TeamB]" wrote: >> > string command("dir h*.txt"); >> > system(command.c_str()); >> >> Thanks for the help. I tried the command but ran into two problems. >> >> First, system does not respond to the cd command. >> string command("cd .."); >> system(command.c_str()); >> >> But GetCurrentDir() returns the same value before and after the system command. > >The system does respond to the change directory command, it is just >that the result is not what you wanted or expected. The system() >function causes a new instance of the command interpreter to be >launched. That command interpreter processes the argument to the >change directory command and changes its current directory. Then that >instance of the command interpreter exits. > >In MS-DOS/Windows, as in UNIX/Linux, a child process changing its >current directory has no effect at all on the parent process (your >program calling system()) current directory. > >If you want to change your program's current directory, you need to >use the proper MS-DOS or Windows system call, the system() function >can't do it for your. Oops my other post didn't show up. Is there a way to create a shell instance as a variable, so then it can remember it's state? Like Shell shell; shell.system(command.c_str()); printf("%s", shell.GetCurrentDir()); // may change! >> The system command does not always respond to the new text color. >> >> textcolor(YELLOW); >> cprintf("dir"); >> textcolor(LIGHTCYAN); >> cprintf("\r\n"); >> system("dir"); >> >> The last command executes in the color YELLOW, but it should execute in the color LIGHTCYAN. >> >> Thanks. > >Don't know about this one. What version of Borland compiler and what >version of DOS or Windows are you running it under? Windows ME running Borland C++ Builder 6 personal edition, build 10.161. Thanks. .