File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /* *
2+ 之所以存在这个文件来执行bat文件,是因为实际操作发现,没有办法用cmd参数出入bat文件让它执行。
3+ */
4+ #include < stdio.h>
5+ #include < iostream>
6+ #include < fstream>
7+ #include < windows.h>
8+ using namespace std ;
9+
10+ int main (int argc, char * args[]){
11+ if (argc != 2 ){
12+ cout << " command line must like this:" << endl;
13+ cout << " execBatFile[.exe] batFilePath" << endl;
14+ return 0 ;
15+ }
16+ char * filePath = args[1 ];
17+ ifstream f (filePath);
18+ if (NULL == f){
19+ cout << " batFilePath error!" << endl;
20+ return 0 ;
21+ }
22+ string lineChars, gotChars;
23+ while (EOF != f.peek ()){
24+ lineChars = " " ;
25+ char peekChar = f.peek ();
26+ while (EOF != peekChar && ' \n ' != peekChar){ // /windows下面换行是\r\n,程序中只需要处理\n 因为\n写入文件的时候会自动写入\r\n,读入的时候也是\r\n自动修改为\n
27+ f >> gotChars;
28+ if (lineChars.length () > 0 )
29+ lineChars += " " ;
30+ lineChars += gotChars;
31+ peekChar = f.peek ();
32+ }
33+ f.get (); // 将末尾的换行读进来
34+ if (" " == lineChars)
35+ continue ;
36+ if (lineChars[0 ] == ' @' && lineChars.length () >= 4 && lineChars.substr (1 ,3 ) == " rem"
37+ || lineChars.length () >= 3 && lineChars.substr (0 ,3 ) == " rem" ) // 注释,不打印
38+ continue ;
39+ cout << " command line: " << lineChars << endl;
40+ system (lineChars.c_str ());
41+ }
42+ return 0 ;
43+ }
You can’t perform that action at this time.
0 commit comments