Hi, I was wondering how to open a bat file at the end of a program. we'll say the file was test.bat, and it was in c:\ ... any help would be greatly appreciated!!!!!!
Hi, I was wondering how to open a bat file at the end of a program. we'll say the file was test.bat, and it was in c:\ ... any help would be greatly appreciated!!!!!!
What means open ?Originally Posted by twomers
if you mean run
KurtCode:system("c:\\test.bat");
that's perfect Kurt!!! thanks a mil!!!!!!!!!!!!!!!
It depends on what you want to do.
Code:#include <iostream> //cout #include <fstream> //ifstream, ofstream #include <string> using namespace std; int main() { //read from file: ifstream inFile("C:\\TestData\\test.bat"); if(!inFile) { cout<<"couldn't open file"<<endl; return 1; } string str; inFile>>str; cout<<str<<endl; inFile.close(); //append text to the end of the file: ofstream outFile("C:\\TestData\\test.bat", ios::app); outFile<<endl<<"some text"; return 0; }
For system() you need to include <cstdlib>.
If you want to run it in a seperate DOS window, you can usually use
Code:system("start test.bat");
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.