Copy command in DOS

I am writing a program which contains a file copy operation. To do this, I used something like this:

int resultCode = system ("copy source.txt destDir");

But I don't know how to interpretate the result code, also is it possible to show the user the error message that the copy command generates?

Thank you very much!
[348 byte] By [kyoko] at [2007-11-18 22:15:41]
# 1 Re: Copy command in DOS
Use "CreateProcess", and pass in handles for stdin, stdout, stderr. Then you can capture any output the process dumps to the screen.

As for the return code of copy, I don't know what they are. Have you tried a Google search?

Viggy
MrViggy at 2007-11-11 1:04:26 >
# 2 Re: Copy command in DOS
Or you could just use the CopyFile() API function and GetLastError() if it fails.
Bond at 2007-11-11 1:05:26 >
# 3 Re: Copy command in DOS
I am writing a program which contains a file copy operation. To do
int resultCode = system ("copy source.txt destDir");

But I don't know how to interpretate the result code, also is it possible to show the user the error message that the copy command generates?

From MSDN:

Return Value

If command is NULL and the command interpreter is found, the function returns a nonzero value. If the command interpreter is not found, it returns 0 and sets errno to ENOENT. If command is not NULL, system returns the value that is returned by the command interpreter. It returns the value 0 only if the command interpreter returns the value 0. A return value of 1 indicates an error, and errno is set to one of the following values:

E2BIG

Argument list (which is system-dependent) is too big.

ENOENT

Command interpreter cannot be found.

ENOEXEC

Command-interpreter file has invalid format and is not executable.

ENOMEM

Not enough memory is available to execute command; or available memory has been corrupted; or invalid block exists, indicating that process making call was not allocated properly.

Other than that...is there any reason why you need to use the DOS way? Otherwise, I would simply second Bond on this one...
Andreas Masur at 2007-11-11 1:06:28 >
# 4 Re: Copy command in DOS
Or you could just use the CopyFile() API function and GetLastError() if it fails.
D'OH! Forgot about that!!!

:blush:

I was concertrating on the "system" part of the OP's question!

Viggy
MrViggy at 2007-11-11 1:07:28 >