Hi All,
[Application & code back ground]
I have an MFC application which is executing on Windows Server 2008 R2 in WOW64 environment. In which on user input it defragments the selected drive on the disk. I initiated the process(.i.e. cmd /c defrag –v c:) of defragmentation using the CreateProcess() API, along with this to display output of the process on the main screen I created the pipe using CreatePipe() API. I used PeekNamedPipe() & ReadFile() API to get the output and display.
[Problem Area]
When the process is launched I am not getting the initial output as below:
Microsoft Disk fragmenter
Copyright © 2007 Microsoft Crop.
Invoking defragmentation on (C:)….
I constantly monitor the output of the process while it is under progress but not able to get any thing as output in the pipe. It seem the process is not doing any thing and appears as if the application is not responding. But after certain period of time, once the process is about to completed I get result along with the initial data.
[Sample code]
//Pipe created
if(0 == ::CreatePipe(&l_hStdOutRead, &l_hStdOutWrite, &l_SecurityAttribute, (DWORD)NULL))
{
//Error code
}
//Process created/launched
if (0 == ::CreateProcess(NULL, (LPTSTR)f_csProcessName,
&l_stSecurityAttributes, NULL, TRUE, CREATE_NO_WINDOW, NULL,NULL, &l_StartupInfo, &l_CmdPI))
{
//Error code
}
//Read output
if (0 == ::PeekNamedPipe(m_hStdOutRead, l_cArrPeekBuffer, (DWORD)NULL, (LPDWORD)NULL, &l_dwAvailable, (LPDWORD)NULL))
{
//Return to read again
}
if (MPLUSFALSE == ::ReadFile(m_hStdOutRead, l_cArrOutput,
min(BUFFER_SIZE - 2, l_dwAvailable), &l_dwRead, NULL) || !l_dwRead)
{
//error code
}
//Display data.
If any one is aware of similar problem or worked on the similar issue please let me know the solution.
Thanks in Advance,
Ganesh