Parse a filename in gSystem->Exec()

Dear rooters,

I am trying to give a root macro an argument of an ascii file. This filename will be used later to run some external commands using gSystem->Exec() and to create some histograms. How can I do that?

A simple code is the following

[code]void mcnp2root(char* filename){

cout << “File” << filename << endl;
gSystem->Exec(“awk ‘/cell 5/{flag=1;next}/total/{flag=0}{if(flag==1){flag++;next}}flag’ filename > filename_out.txt”);

// (2) Read the ascii files and create the histograms
double En, F, erF;
ifstream in;
in.open(“filename_out.txt”);
if(!in){
cout << “File not found” << endl;
}
int l=0;
while(!in.eof()){
in >> En >> F >> erF;
ebins[l] = En;
flux[l] = F;
flux_error[l] = erF;
l++;
}

}[/code]

Thanks a lot in advance!

I found a way, but there are some issues. i could use TString::Format(. However when I do it I get the following warnings

[quote]warning: cannot pass objects of non-POD type ‘class TString’ through ‘...’ /afs/cern.ch/user/a/astamato/private/NTUA/234U/MCNP/./mcnp2root.C:16: warning: format ‘%s’ expects type ‘char*’, but argument 3 has type ‘TString*’[/quote]

I tried using

fileout_234_front.c_str() but I get the error

although I include all necessary header files…

My code is

[code]void mcnp2root(char* filename, int cycle){

// (0) Declaration of input/output files

TString filein(TString::Format(“%s_%i.o”, filename, cycle));
TString fileout_234_front(TString::Format(“%s_%i_234U_front.txt”, filein.Data(), cycle));//

// (1) Execute awk to get the flux ascii files

gSystem->Exec(TString::Format("awk '/cell  5/{flag=1;next}/total/{flag=0}{if(flag==1){flag++;next}}flag' %s > %s", filein.Data(), fileout_234_front));//<------ two warnings

}[/code]

Any idea on how to fix it?

The equivalent to .c_str() for TString is .Data()

That is correct…
Thanks a lot!!!