能力值:
( LV2,RANK:10 )
|
-
-
2 楼
命令获取一些参数很实用
最后于 2023-3-17 15:59
被SnowRen编辑
,原因:
|
能力值:
( LV2,RANK:10 )
|
-
-
3 楼
最近写的linux程序用的就是popen
|
能力值:
( LV2,RANK:10 )
|
-
-
4 楼
這把戲,可以參考 https://github.com/terrylao/WinCat
|
能力值:
( LV2,RANK:10 )
|
-
-
5 楼
good
|
能力值:
( LV7,RANK:102 )
|
-
-
6 楼
说白了就是缺少一些基础的库,C++这玩意确实就是这样子的
|
能力值:
( LV9,RANK:195 )
|
-
-
7 楼
C++开发大型项目,维护愁死人
|
能力值:
( LV2,RANK:10 )
|
-
-
8 楼
std::string ExecuteCommandLine(std::string cmd)
{
std::string cmd_result = std::string();
HANDLE hReadPipe, hWritePipe;
SECURITY_ATTRIBUTES saAttr;
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;
if (!CreatePipe(&hReadPipe, &hWritePipe, &saAttr, 0))
{
exit(1);
}
STARTUPINFOA si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.hStdError = hWritePipe;
si.hStdOutput = hWritePipe;
si.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
si.wShowWindow = SW_HIDE;
if (!CreateProcessA(NULL, (LPSTR)cmd.c_str(), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
{
exit(1);
}
CloseHandle(hWritePipe);
char psBuffer[0x2000] = { 0 };
DWORD dwRead;
BOOL bSuccess = FALSE;
while (bSuccess = ReadFile(hReadPipe, psBuffer, sizeof(psBuffer), &dwRead, NULL))
{
if (dwRead == 0)
{
break;
}
cmd_result += psBuffer;
memset(psBuffer, 0, 0x2000);
}
int closeReturnVal = 0;
if (GetExitCodeProcess(pi.hProcess, (LPDWORD)&closeReturnVal))
{
printf("\nProcess returned %d\n", closeReturnVal);
}
else
{
printf("Error: Failed to read the pipe to the end.\n");
}
CloseHandle(hReadPipe);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return cmd_result;
}
API也简单.
|
能力值:
( LV8,RANK:147 )
|
-
-
9 楼
_popen也不太好,我最近遇到一个问题,win32 GUI程序,使用_popen无法隐藏命令行,最后还是老老实实用API管道搞的
|
能力值:
( LV4,RANK:50 )
|
-
-
10 楼
Boost.Process
|
|
|