I need to develop a piece of code in an old legacy Visual C++ 6.0 system. I am invoking a stand-alone executable via a system call. This exe is supposed to create a file if processing goes OK or not create one if it fails. The name of the file to create is passed to the exe as a command-line argument. When I invoke this exe from a console window, in a certain case it fails to process and does not create the output file. However, when I invoke the same exe through the system call form my VC++ system, it fails but also creates an empty file. I invoke it using

CreateProcess()

. I have two questions:
1. Why is it creating the empty file?
2. To check for success/failure I am currently doing this:

if( _access( strDestFile, 0 ) == -1 ) {
// file does not exist
}

I guess I need to also check if the file is non-empty. What's the easiest way of doing it in VC++ 6.0?

Thanks!

>> Why is it creating the empty file?
I'd suggest debugging the program and try to see where it fails and why.

You could use
_stat() to check both the file's existence and its size in one go.

Does it behave this way for both debug and release versions?

Good info from mitrmkar. A big +1 for using the debugger to step through the code and find where it is failing and what's going on when the file is being created. Set a break point or run-to-cursor where the test is done and start stepping through code from there.

Also, GetFileSize() might be another option for you.

>> Why is it creating the empty file?
I'd suggest debugging the program and try to see where it fails and why.

You could use
_stat() to check both the file's existence and its size in one go.

_stat worked, thanks

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.