Shell command execution and return value

Dear all,

I don’t understand something with the TSystem commands to execute a shell command.

Here is a shell session with a successful and a failed command :

[code]>ls

echo ? 0 ls ---- <error> echo ?
2[/code]

In ROOT, I get different return code :

root [7] int i = gSystem->Exec("ls") <output> root [8] i (int)0 root [9] int i = gSystem->Exec("ls --------") <error> root [10] i (int)512
You see that I get 512 instead of 2. Why is that ?

Related question : I can get the output of a command by using GetFromPipe(). How to get both the output and the return value ?

Thank you
Barth

In case of Unix … the TUnixSystem::Exec simply calls the standard “system” library function. For details of the “return value” see:
man 3 system
man 2 wait
(Try also to print “WEXITSTATUS(512)”.)

Looking at the source code of the TSystem::GetFromPipe … I’m afraid that the “return value” from the final TUnixSystem::ClosePipe call is lost. You would need to write your own routine which “mimics” the original one, but which also saves this value somewhere (for later usage in your code).

Hello,

Thank you for your reply. I have created a Savannah ticket to ask for an improved GetFromPipe method.

For the time being, and in order not to duplicate and modify a ROOT method, I will simply use Exec and save the output in a file.

Best regards,
Barth