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!!!!!!
Printable View
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 ?Quote:
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");