Hi Jianglai, you can use pipes to run the command and directly read the output, for example: ... FILE *p = gSystem->OpenPipe(Form("ps -u %s", user), "r"); TString out; Bool_t myproc = kFALSE; while (out.Fgets(p)) { if (out.Index("myprog") != kNPOS) { myproc = kTRUE; break; } } gSystem->ClosePipe(p); ... TString::Fgets() is a recent addition so use the latest version. Cheers, Fons. > Dear ROOTers, > > I am implementing a launcher button on a ROOT GUI program to invoke > another executable. But I like to test whether the process has been > running already. A quick and dirty solution I am using is > (in pseudo-code language) > > -- gSystem->Exec("ps -u user | grep program >.tmp"); > -- Parse the tmp file and find if program exists > > Is there a better way in TSystem (or whatever ROOT class) that > might handle the system calls in a more elegant way? > > Thanks in advance! > > Jianglai > -- Org: CERN, European Laboratory for Particle Physics. Mail: 1211 Geneve 23, Switzerland E-Mail: Fons.Rademakers@cern.ch Phone: +41 22 7679248 WWW: http://www.rademakers.org/fons/ Fax: +41 22 7679480
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:15 MET