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!!!

Recommended Answers

All 2 Replies

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
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.