TSystem::GetFromPipe returned 256

Hello,

I am trying to understand why the following code produces an error:

 gSystem->Exec("echo abc > f1.txt");
 gSystem->Exec("echo xyz > f2.txt");
 gSystem->GetFromPipe("diff -s -q f1.txt f2.txt");

The error is:

If the two files are identical, then no error is produced.

If anybody has a clue about why the code produces an error, please, let me know.

Thank you,
Siarhei.

Hi,

TSystem::GetFromPipe because it returns the output as a string as not place to return the error code of the underlying command. In the case of diff, it returns a non zero error code if the two files are different.

To avoid the message, you will need to use directly OpenPipe and ClosePipe, similar to the implementation of GetFromPipe:

[code] TString out;

FILE *pipe = OpenPipe(command, “r”);
if (!pipe) {
SysError(“GetFromPipe”, “cannot run command “%s””, command);
return out;
}

TString line;
while (line.Gets(pipe)) {
if (out != “”)
out += “\n”;
out += line;
}

Int_t r = ClosePipe(pipe);
if ® {
// Ignore the error.
// Error(“GetFromPipe”, “command “%s” returned %d”, command, r);
}
[/code]

Cheers,
Philippe.

Thank you, Philippe!

That is what I did. It is strange though that “diff” returns an error code even if the comparison of input files finished successfully.

[quote]It is strange though that “diff” returns an error code even if the comparison of input files finished successfully.[/quote]It is completely intentional on the part of the diff developer. This way you can detect (in a shell script) whether two files are identical or not without have to parse the output.

Cheers,
Philippe.