Please tell me why only the first process created in Windows with a for loop is successfully created. QAQ
is an experiment of operating system, and the experimental requirements are as follows:
In the
Windows environment
, use the high level language programming environment(limited to VS or VC environment) to invoke the related system call(CreateProccess, system API) to implement a system that includes "process creation, File read and write "application.
has a text file CommandList.txt with explanatory text on the first line: This file was last opened and run on 20190407. Starting with the second line, each line is the name of an executable program(including the path). Write an application that opens the file, executes each program in sequence, and updates the date in the first line of the file.
// 创建子进程
for(int i=0; i<path.size(); ++i){
STARTUPINFO si = {sizeof(si)};
PROCESS_INFORMATION pi;
// path是vector<string>向量,保存每行路径,p作为创建进程的lpCommandLine
char p[path[i].size()];
cout<<"new path "<<i<<": ";
for(int j=0; j<path[i].size(); ++j){
p[j] = path[i][j];
cout<<p[j];
}
cout<<endl;
//每个路径都创建一个新进程打开
bool ret = CreateProcess(NULL, p, NULL, NULL, false, 0, NULL, NULL, &si, &pi);
if(ret) {
cout<<"子进程id: "<<pi.dwProcessId<<endl;
}
else {
cout<<"子进程创建失败!失败原因:"<<GetLastError()<<endl;
}
}
Run result:
GetLastError()=2, I checked that the file did not exist, but my path is correct. Now I just don't know what is wrong orz
0 Answer
No answer yet
这家伙很懒,什么都没留下...