plennon
asked on
diff command
I am comparing 2 files using diff
Diff –s filename1 filename2
This returns ‘files filename1 and filename2 are identical’
I am doing this through a c program using
sprintf(command, "diff -s filename1 filename2");
system(command);
I want to check the return value and display a message saying the files were identical or not
Preferably using exit(0); if possible
can anyone help
thanks
Diff –s filename1 filename2
This returns ‘files filename1 and filename2 are identical’
I am doing this through a c program using
sprintf(command, "diff -s filename1 filename2");
system(command);
I want to check the return value and display a message saying the files were identical or not
Preferably using exit(0); if possible
can anyone help
thanks
ASKER
it's how to get the return value that i can't figure out
in my c code i have
sprintf(diffcommand, "diff -s filename1 filename2");
system(diffcommand);
it produces the following message
"files filename1 and filename2 are identical"
i don't want this to be displayed i only want to have an if statement that will display pass if they are identical (return value 0) or fail if not (return is nonzero)
it's actually the c code i'm looking for although i've posted this in the unix section
thanks
in my c code i have
sprintf(diffcommand, "diff -s filename1 filename2");
system(diffcommand);
it produces the following message
"files filename1 and filename2 are identical"
i don't want this to be displayed i only want to have an if statement that will display pass if they are identical (return value 0) or fail if not (return is nonzero)
it's actually the c code i'm looking for although i've posted this in the unix section
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
use popen if you want to read in the results of diff ...
if all you want is return status of diff, then system returns exactly that
RETURN VALUE
The value returned is -1 on error (e.g. fork failed), and
the return status of the command otherwise. This latter
return status is in the format specified in wait(2).
Thus, the exit code of the command will be WEXITSTA
TUS(status). In case /bin/sh could not be executed, the
exit status will be that of a command that does exit(127).
If the value of string is NULL, system() returns nonzero
if the shell is available, and zero if not.
system() does not affect the wait status of any other
children.
Sunnycoder