Reading a file through http

Hi,

I wonder if ROOT provides an easy mechanism to read a text file from the web (http). Please, note I do not want to read a ROOT file but a plain text one. I know I could do the conversion, but this files are provided in text format by some one else and my live would be easier if I did not have to copy&convert them.

Cheers,

Isidro

Hi,

As far as I know (and I’m not a root developer), Root does not have this ability. You can use commands like wget to easily grab the files so that you can use them.

If you’re really gung-ho on not grabbing the file ahead of time, you could do something as wacky as this (although I can’t see a good reason for actually doing this :smiley: )

   string command = "curl http://some.web.page/somefile.txt";

   FILE *fpipe;
   if ( ! (fpipe = (FILE*) popen (command.c_str(), "r") ) )
   {  // If fpipe is NULL
      cerr << "Problems with pipe" << endl;
      exit(1);
   } // if problem

   const int kLongLine = 1001;
   char c_line[kLongLine+1]; // make sure this line is long enough
   while ( fgets( c_line, sizeof line, fpipe))
   {
      string line (c_line);
      // if this line is not long enough, let us know
      assert (line.length() < kLongLine - 1);
      // processLineHere
      cout << line;
   } // while next line
   cout.flush();
   pclose(fpipe);

Cheers,
Charles

p.s. there may be a more c++ friendly way of using pipes but I’m not familiar with it…

Hi Charles,

Thankyou very much for your suggestion. Actually you reminded me of the TSystem::GetFromPipe(char* command) method that should do the work, if not perfect, at least easy. Ideally I would like to have some class inheriting from istream, etc…

One can use it in combination with curl, like you suggested in your code, as:

TString theFileContent = gSystem::GetFromPipe("curl http://some.web.in/which/you/haveTheInfo.txt");

Hope this helps others. Cheers,

Isidro