这个是在网上搜索的,但还是获取不到。
那位大神给改一下,好久没写C了
int GetRun()
{
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
HANDLE outHandle;
outHandle = CreateFile(L"aa.txt", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, CREATE_ALWAYS, 0, NULL);
PROCESS_INFORMATION processInfo;
STARTUPINFO startUpInfo;
memset(&startUpInfo, 0, sizeof(STARTUPINFO));
memset(&processInfo, 0, sizeof(PROCESS_INFORMATION));
startUpInfo.cb = sizeof(STARTUPINFO);
startUpInfo.dwFlags = STARTF_USESTDHANDLES;
startUpInfo.wShowWindow = SW_SHOWNORMAL;
startUpInfo.hStdOutput = outHandle;
if (!CreateProcess(L"Coreinfo.exe", NULL, NULL, NULL, FALSE,
CREATE_NEW_CONSOLE, NULL, NULL,
&startUpInfo, &processInfo)){
CloseHandle(outHandle);
printf("open hello.exe error\n");
}
else
{
DWORD filesize = 1000;
char * buffer = (char *)malloc(filesize + 1);
memset(buffer, 0, filesize + 1);
DWORD readsize;
ReadFile(outHandle, buffer, filesize, &readsize, NULL);
buffer[filesize] = 0;
printf("1111111 - %s\n", buffer);
free(buffer);
WaitForSingleObject(processInfo.hProcess, INFINITE);
printf("open hello.exe ok\n");
CloseHandle(outHandle);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
}
return 0;
}
用匿名管道就可以,CreateFile是产生命名管道的,而且文件名也不正确。请搜索匿名管道和命名管道即可。