Подскажите, пожалуйста.Мне нужно создать 2 exe-файла: test1.exe и test2.exe. кладем в разные папки, пусть первый кладем в c:\home\test1.exe
а второй в c:\work\test2.exe
. пишем два текстовых файла:
test1.txt:
c:\home\test1.exe
c:\work\test2.exe
test2.txt:
c:\work\test2.exe
c:\home\test1.exe
затем пишем программу prog.exe которая принимает аргументом путь к одному из двух текстовых файлов. результаты работы такие:
prog.exe test1.txt: запуск сначала test1, затем test2
prog.exe test2.txt: запуск сначала test2, затем test1
Вопрос, как запустить .exe
файлы с прочитанного текстового файла?
#include <iostream>
#include <fstream>
#include <process.h>
using namespace std;
int main(int argc, char *argv[]) {
cout << "argc = " << argc << endl;
for (int i = 0; i < argc; i++) {
cout << "Argument: " << i << " = " << argv[i] << endl;
}
if (argc != 2) {
cout << "Error" << endl;
exit(-1);
}
char ch;
ifstream infile;
infile.open(argv[1]);
if (!infile) {
cout << "errrrror: cant open a file" << argv[1];
exit(-1);
}
while (infile) {
infile.get(ch);
cout << ch;
}
cout << endl;
system("pause");
return 0;
}