I am writing a macro for a ROOT/CINT based program that convert raw data to TTree.
In this macro I would like to test if my raw data file is not open somewhere else (on the network typically), especially by the acquisition system (data being wrote).
and parse the output of lsof to check if the file of interest is not present. But TSystem::Exec only return an integer. Is there any way to do this ? Like you can do it in Perl for example…
Thank for this solution. I prefer this since updating ROOT in my lab is not an easy task (updating is global…).
Concerning the very particular problem I was facing at the beginning of my post, I found a workaround that does not imply streaming the output of the shell command.
I wanted to check if a given file was opened so here is the code I used :
string input_file = "name_of_the_file_to_be_tested";
string condition = "lsof -Fn | grep ";
condition += input_file;
if(gSystem->Exec(condition.c_str())!=0) {
// code if the file is not opened
}