本文整理汇总了C++中Process::ReadFromPipe方法的典型用法代码示例。如果您正苦于以下问题:C++ Process::ReadFromPipe方法的具体用法?C++ Process::ReadFromPipe怎么用?C++ Process::ReadFromPipe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Process
的用法示例。
在下文中一共展示了Process::ReadFromPipe方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExecuteCommand
bool ExecuteCommand(const char* lpszCommand, char* lpszParams, int nTimeout, char** lpszData, int nDataSize)
{
bool bResult = false;
::ZeroMemory(*lpszData, nDataSize);
try
{
Process p;
HANDLE hProcess = p.CreateProcess(lpszCommand, lpszParams);
if (hProcess != 0)
{
DWORD dwResult = WaitForSingleObject(hProcess, nTimeout); // Wait for process to complete
if (dwResult != WAIT_OBJECT_0)
{
bResult = false;
}
else
{
// Read from process's output
p.ReadFromPipe(lpszData, nDataSize);
bResult = true;
}
}
else
bResult = false;
}
catch(...)
{
bResult = false;
}
return bResult;
}
示例2: Execute
bool CacheDumpControl::Execute(const char* lpszPSExecPath, const char* lpszDumpPath, char* lpszMachine, bool bIs64Bit, char* lpszPipeName)
{
char* lpszCmdLineFormat;
int nArgSize;
char* lpszStopCmdLine;
char* lpszParams;
bool result = false;
if (lpszPipeName == NULL)
{
// Set the local cachedump path
if (!bIs64Bit)
lpszCmdLineFormat = "%s\\cachedump.exe";
else
lpszCmdLineFormat = "%s\\cachedump64.exe";
nArgSize = _scprintf(lpszCmdLineFormat, lpszDumpPath);
lpszStopCmdLine = new char[nArgSize + 1];
memset(lpszStopCmdLine, 0, nArgSize + 1);
_snprintf_s(lpszStopCmdLine, nArgSize, strlen(lpszCmdLineFormat)-1+strlen(lpszDumpPath), lpszCmdLineFormat, lpszDumpPath);
// Now set the parameters
lpszCmdLineFormat = " -v";
lpszParams = new char[nArgSize + 1];
memset(lpszParams, 0, nArgSize + 1);
_snprintf_s(lpszParams, nArgSize, strlen(lpszCmdLineFormat)-1, lpszCmdLineFormat);
}
else
{
lpszStopCmdLine = new char[strlen(lpszPSExecPath) + 1];
memset(lpszStopCmdLine, 0, strlen(lpszPSExecPath) + 1);
strncpy_s(lpszStopCmdLine, strlen(lpszPSExecPath) + 1, lpszPSExecPath, strlen(lpszPSExecPath));
if (!bIs64Bit)
lpszCmdLineFormat = " -c -n %s %s \"%s\\cachedump.exe\" -v";
else
lpszCmdLineFormat = " -c -n %s %s \"%s\\cachedump64.exe\" -v";
nArgSize = _scprintf(lpszCmdLineFormat, lpszPipeName, lpszMachine, lpszDumpPath);
lpszParams = new char[nArgSize + 1];
memset(lpszParams, 0, nArgSize + 1);
_snprintf_s(lpszParams, nArgSize, strlen(lpszCmdLineFormat)-3+strlen(lpszPipeName)+strlen(lpszMachine)+strlen(lpszDumpPath), lpszCmdLineFormat, lpszPipeName, lpszMachine, lpszDumpPath);
}
try
{
Process p;
HANDLE hProcess = p.CreateProcess(lpszStopCmdLine, lpszParams);
if (hProcess != 0)
{
DWORD dwResult = WaitForSingleObject(hProcess, 1200000); // Wait 20 minutes for process to complete
if (dwResult != WAIT_OBJECT_0)
{
Log.CachedReportError(m_nCacheID, CRITICAL, "Warning: cachedump did not complete in a timely manner - exiting");
result = false;
}
else
{
// Read from process's output
char* szResult;
int nSize = 65535;
szResult = new char[nSize];
memset(szResult, 0, nSize);
p.ReadFromPipe(&szResult, nSize);
// Was it successful?
if (strstr(szResult, "successfully removed") != NULL)
{
// Success
// Write results to a file
size_t nLen = strlen(lpszMachine) + 10; // 10 chars accounts for ".cachedump" extension
char* szTempFilename = new char[nLen + 1];
memset(szTempFilename, 0, nLen + 1);
_snprintf_s(szTempFilename, nLen, strlen(lpszMachine)+10, "%s.cachedump", lpszMachine);
std::ofstream outputFile(szTempFilename, std::ios::out | std::ios::trunc);
outputFile.write((const char*)szResult, (DWORD)strlen(szResult));
outputFile.close();
delete [] szTempFilename;
Log.CachedReportError(m_nCacheID, CRITICAL, "Cache dumped successfully\n", lpszMachine);
result = true;
}
else
{
// Failed
Log.CachedReportError(m_nCacheID, CRITICAL, "Failed to dump cache (the text returned follows):\n%s", szResult);
result = false;
}
delete [] szResult;
}
}
else
result = false;
}
catch(...)
{
result = false;
//.........这里部分代码省略.........