【发布时间】:2016-11-18 10:50:44
【问题描述】:
我现在正试图从我用 C++ 编写的应用程序中调用 .exe 我试图调用的 exe 是一个 Kermit 程序 (k95.exe) - 一个文件传输应用程序。
在不使用 C++ 的情况下,我可以在 Kermit 程序中输入命令并且它可以工作。
但是,现在我尝试使用CreateProcess() 在我的应用程序中调用这个“Kermit”程序。
在这个阶段,我可以成功调用“Kermit”程序。 Kermit 应用程序能够成功启动。
现在,我们想通过我的 C++ 应用程序将“Take connect.txt”键入控制台,但我们不知道如何继续。
我知道我们可以传入命令CreateProcess(),有点像传递函数参数,但我不打算立即关闭这个 Kermit 程序。
在这两者之间,我可能还想将它用于其他操作,例如下载或上传文件。
我们无法做到以上所有,因为CreateProcess() 不返回窗口句柄。
注意事项
上面使用的“Take”是k95.exe的命令之一
-
我的 CreateProcess 函数位于:
bool LaunchKermitExe( const char path, char cmdLine) { STARTUPINFO si; SECURITY_ATTRIBUTES saProcess, saThread; PROCESS_INFORMATION piProcess; bool bSuccess; DWORD lasterr; // setup STARTUPINFO struct ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); // make new process handle inheritable saProcess.nLength = sizeof(saProcess); saProcess.lpSecurityDescriptor = NULL; saProcess.bInheritHandle = TRUE; // make the new thread handle not inheritable saThread.nLength = sizeof(saThread); saThread.lpSecurityDescriptor = NULL; saThread.bInheritHandle = FALSE; bSuccess = CreateProcess(path, cmdLine, NULL, NULL,TRUE, 0, NULL, NULL, &si, &piProcess); lasterr = GetLastError(); // now close handles to detach the process CloseHandle(piProcess.hThread); CloseHandle(piProcess.hProcess); return bSuccess; }
【问题讨论】:
标签: c++ winapi createprocess