0

This is VC++ 6.0 code running on a Windows Server 2003 SP2 machine.
1. I launch an external exe from my code using CreateProcess()
2. This process creates a file on disk
3. I do rc = WaitForSingleObject(procInfo.hProcess,INFINITE);
4. rc is returned as WAIT_OBJECT_0
5. int result = _stat( strDestFile, &buf ) where strDestFile is the file from step #2
6. I get buf.st_size as 0. However, when I execute the same exe as in step 1 standalone from a console window, it generates the file fine and it's not empty.

QUESTION: is it possible that _stat is returning incorrect info? Is there a more reliable way to check for non-0 size? Is there a way to check whether strDestFile has been properly closed by the external exe?

Thanks much!!!

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by ilyaz
0

Seems like this to me
http://en.wikipedia.org/wiki/Race_condition

> 5. int result = _stat( strDestFile, &buf ) where strDestFile is the file from step #2
> 6. I get buf.st_size as 0
Ah, but what was in result?

if( result != 0  && errno == ENOENT) {
	// file does not exist
} else if ( buf.st_size == 0)
	// exists but empty
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.