Subj : Re: How to execute a shell command To : borland.public.cpp.borlandcpp From : Jack Klein Date : Mon Feb 02 2004 01:55 am On 1 Feb 2004 22:54:36 -0800, "Siemel Naran" wrote in borland.public.cpp.borlandcpp: > > "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. > 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? -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq .