Sunday, August 2, 2009

Run a new console or prompt from a c++ console application?

I have been trying unsuccesfully to do two things: have my console application run a new console window, and use command prompt functions in my console application.

Run a new console or prompt from a c++ console application?
Well the trick is to use the system() function to pass commands to the command prompt from your program. To run another program then all you need is the "start" command. Here is an example...





int main()


{


char answer;





cout %26lt;%26lt; "Want to run another command prompt? (y/n)" %26lt;%26lt; endl;


cin %26gt;%26gt; answer;





if (answer == 'y') {


system("start cmd");


}


else { exit; }





return 0;





}








This will simply launch another command window while your program (running in a command window itself) is executing.. if the user types the letter 'y' that is.





Enjoy!
Reply:while the command prompt is up will my program continue running the remaining code or will it wait until i close the command prompt? Report It



No comments:

Post a Comment