Violation with command gRoot->ProcessLine(Form(".! ls > tmpfiles.txt"))

I can reproduce this error
using the commande su ilaim_u ( generic user used to avoid linux right conflicts)
then typing the command
module load root/5.34.14
and lauchin root
using a command as simple as gROOT->ProcessLine(Form(“.! ls > tmpfiles.txt”))

In fact the file is created but I get a violation error

Using the default version of Root for the simple test simple work ( but this version is incompatible awith the ILAIM sofware )
__
Please read tips for efficient and successful posting and posting code

Please fill also the fields below. Note that root -b -q will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug from the ROOT prompt to pre-populate a topic.

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Try

gROOT->ProcessLine(TString::Format(“.! ls > tmpfiles.txt”))

well actually in your case, the following is enough

gROOT->ProcessLine(“.! ls > tmpfiles.txt”)

This is a simplified test I made outside of the complete software ( juste calling root and typing the command. but in My sotware called ILAIM I need the format.
Note that it was working before using the software ILAIM through a sudo command. So It seems to be related a linux right Pb but I don’t find where…
With your simplified commanded

gROOT->ProcessLine(“.! ls > tmpfiles.txt”)

I also get the violation

vinchon-thi@cadux-login01:~$ su ilaim_u
Password: 
ilaim_u@cadux-login01:/home/nucleon/vinchon-thi$ module load root/5.34.14
ilaim_u@cadux-login01:/home/nucleon/vinchon-thi$ root
  *******************************************
  *                                         *
  *        W E L C O M E  to  R O O T       *
  *                                         *
  *   Version   5.34/14  16 December 2013   *
  *                                         *
  *  You are welcome to visit our Web site  *
  *          http://root.cern.ch            *
  *                                         *
  *******************************************

ROOT 5.34/14 (heads/v5-34-00-patches@v5-34-13-131-gd110ad3, May 04 2021, 10:29:00 on linuxx8664gcc)

CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] gROOT->ProcessLine(.! ls > tmpfiles.txt)
Warning: Illegal numerical expression .!ls>tmpfiles.txt (tmpfile):1:
Warning: Illegal numerical expression .!ls>tmpfiles.txt (tmpfile):1:
Warning: Illegal numerical expression .!ls>tmpfiles.txt (tmpfile):1:
Warning: Illegal numerical expression .!ls>tmpfiles.txt (tmpfile):1:
Warning: Illegal numerical expression .!ls>tmpfiles.txt (tmpfile):1:
Warning: Illegal numerical expression .!ls>tmpfiles.txt (tmpfile):1:
Warning: Illegal numerical expression .!ls>tmpfiles.txt (tmpfile):1:
Warning: Illegal numerical expression .!ls>tmpfiles.txt (tmpfile):1:
Warning: Illegal numerical expression .!ls>tmpfiles.txt (tmpfile):1:
Warning: Illegal numerical expression .!ls>tmpfiles.txt (tmpfile):1:
Warning: Illegal numerical expression .!ls>tmpfiles.txt (tmpfile):1:
Error: Can't call TROOT::ProcessLine(.!ls>tmpfiles.txt) in current scope (tmpfile):1:
Possible candidates are...
public: Long_t TROOT::ProcessLine(const char* line,Int_t* error=0);
*** Interpreter error recovered ***
root [1] gROOT->ProcessLine(".! ls > tmpfiles.txt")
Error: cannot open pipe output file tmpfiles.txt!
ls: cannot open directory .: Permission denied

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00002ad42c3fd46c in waitpid () from /lib64/libc.so.6
#1  0x00002ad42c37af62 in do_system () from /lib64/libc.so.6
#2  0x00002ad42b283992 in TUnixSystem::StackTrace() () from /soft/root/5.34.14/lib/root/libCore.so
#3  0x00002ad42b283263 in TUnixSystem::DispatchSignals(ESignals) () from /soft/root/5.34.14/lib/root/libCore.so
#4  <signal handler called>
#5  0x00002ad42c38062d in vfprintf () from /lib64/libc.so.6
#6  0x00002ad42c38b407 in fprintf () from /lib64/libc.so.6
#7  0x00002ad42cf1c1bb in G__process_cmd () from /soft/root/5.34.14/lib/root/libCint.so
#8  0x00002ad42b243276 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /soft/root/5.34.14/lib/root/libCore.so
#9  0x00002ad42b21581a in TApplication::ProcessLine(char const*, bool, int*) () from /soft/root/5.34.14/lib/root/libCore.so
#10 0x00002ad42b9e80fd in TRint::HandleTermInput() () from /soft/root/5.34.14/lib/root/libRint.so
#11 0x00002ad42b2815ee in TUnixSystem::CheckDescriptors() () from /soft/root/5.34.14/lib/root/libCore.so
#12 0x00002ad42b2817a3 in TUnixSystem::DispatchOneEvent(bool) () from /soft/root/5.34.14/lib/root/libCore.so
#13 0x00002ad42b204ce6 in TSystem::InnerLoop() () from /soft/root/5.34.14/lib/root/libCore.so
#14 0x00002ad42b206eeb in TSystem::Run() () from /soft/root/5.34.14/lib/root/libCore.so
#15 0x00002ad42b213d3f in TApplication::Run(bool) () from /soft/root/5.34.14/lib/root/libCore.so
#16 0x00002ad42b9e8d25 in TRint::Run(bool) () from /soft/root/5.34.14/lib/root/libRint.so
#17 0x000000000040107c in main ()
===========================================================


The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x00002ad42c38062d in vfprintf () from /lib64/libc.so.6
#6  0x00002ad42c38b407 in fprintf () from /lib64/libc.so.6

Another test placing user ilaim_u in its home directory

root [0] gROOT->ProcessLine(".! ls  > tmpfiles.txt")
Error: cannot open pipe output file tmpfiles.txt!
ls: write error: Bad file descriptor

 *** Break *** segmentation violation

gROOT->ProcessLine(".! ls  > tmpls4.txt")
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00002ac16c6a446c in waitpid () from /lib64/libc.so.6
#1  0x00002ac16c621f62 in do_system () from /lib64/libc.so.6
#2  0x00002ac16b52a992 in TUnixSystem::StackTrace() () from /soft/root/5.34.14/lib/root/libCore.so
#3  0x00002ac16b52a263 in TUnixSystem::DispatchSignals(ESignals) () from /soft/root/5.34.14/lib/root/libCore.so
#4  <signal handler called>
#5  0x00002ac16c62762d in vfprintf () from /lib64/libc.so.6
#6  0x00002ac16c632407 in fprintf () from /lib64/libc.so.6
#7  0x00002ac16d1c31bb in G__process_cmd () from /soft/root/5.34.14/lib/root/libCint.so
#8  0x00002ac16b4ea276 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /soft/root/5.34.14/lib/root/libCore.so
#9  0x00002ac16b4bc81a in TApplication::ProcessLine(char const*, bool, int*) () from /soft/root/5.34.14/lib/root/libCore.so
#10 0x00002ac16bc8f0fd in TRint::HandleTermInput() () from /soft/root/5.34.14/lib/root/libRint.so
#11 0x00002ac16b5285ee in TUnixSystem::CheckDescriptors() () from /soft/root/5.34.14/lib/root/libCore.so
#12 0x00002ac16b5287a3 in TUnixSystem::DispatchOneEvent(bool) () from /soft/root/5.34.14/lib/root/libCore.so
#13 0x00002ac16b4abce6 in TSystem::InnerLoop() () from /soft/root/5.34.14/lib/root/libCore.so
#14 0x00002ac16b4adeeb in TSystem::Run() () from /soft/root/5.34.14/lib/root/libCore.so
#15 0x00002ac16b4bad3f in TApplication::Run(bool) () from /soft/root/5.34.14/lib/root/libCore.so
#16 0x00002ac16bc8fd25 in TRint::Run(bool) () from /soft/root/5.34.14/lib/root/libRint.so
#17 0x000000000040107c in main ()
===========================================================


The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x00002ac16c62762d in vfprintf () from /lib64/libc.so.6
#6  0x00002ac16c632407 in fprintf () from /lib64/libc.so.6
===========================================================


.q
ilaim_u@cadux-login01:~$ ls -al|grep tmp
-rw-r--r--   1 ilaim_u ilaim_u   362 Jun 28 12:31 tmpfiles.txt
-rw-r--r--   1 ilaim_u ilaim_u   192 Jun 28 13:59 tmpls4.txt
-rw-r--r--   1 ilaim_u ilaim_u   110 Jun 27 16:06 tmpls.txt

Error but file created

Hi @vinchon-thi ,

I am not sure what the root cause of the issue is but I see you are using ROOT 5.34, which is not supported anymore (besides highly critical fixes).

The command seems to work in ROOT 6.28.

Maybe as a workaround you can use gSystem->Exec instead of going through the interpreter only to execute a shell command (not sure that will work if ProcessLine fails, but it might be worth a try).

Cheers,
Enrico

This seems to be related to the redirection of the output. The simplest/safest solution is to add a layer of indirection which will use the shell redirection rather than the CINT indirection.
Use a script marked as executable (named here redirected_ls)

#!/bin/sh

file=$1
shift
ls $* > $file

and use

gROOT->ProcessLine(".! redirected_ls tmpls4.txt .....");

Given this:

Error: cannot open pipe output file tmpfiles.txt!

It might simply be that something in the OS no longer give your access to the target file (i.e. SELinux or alternative) and trying the following might work:

gROOT->ProcsssLine(".! ls /home/username > /var/tmp/tmpfiles.txt");

You have to note that this command is working if I use my personnal account.
the violation appears if I do a su ilaim_u and then a cd to go to ilaim_u directory
it should be noted that a vialation appears but the file is creates.
Could it be related to the fact that the command is called without the second argument ( related to error )

i try redirecting to /var/tmp/testfile.txt but I still got a violation ( even if the file is created)

is there a methodology to use gdb knowing that I call my software in a shell trough a call :
root BC_ILAIM.C
?

so in interpreted mode
Note that what has change is the add before this command of a su ilaim_u
I changed all the rights of the impacted repertory to give rwx authorization to ilaim_u

Hi @vinchon-thi ,

at this point I am not sure this is a ROOT problem? Does it work if we cut out ROOT from the picture and you run the command via standard C or C++ calls such as system?

building a file testSystem.C
#include
#include
#include

int testSystem()
{
std::system(“ls -l >test.txt”); // executes the UNIX command “ls -l >test.txt”
std::cout << std::ifstream(“test.txt”).rdbuf();
}

and calling it trough root seems to work
ilaim_u@cadux-login01:~$ root testSystem.C


  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 5.34/14 16 December 2013 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      http://root.cern.ch            *
    
  •                                     *
    

ROOT 5.34/14 (heads/v5-34-00-patches@v5-34-13-131-gd110ad3, May 04 2021, 10:29:00 on linuxx8664gcc)

CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Processing testSystem.C…
0x279c6d0(int)-2145428960
root [1]
.q
and ceate the file
ilaim_u@cadux-login01:~$ ls -al test.txt
-rw-r–r-- 1 ilaim_u ilaim_u 1526 Jun 29 18:33 test.txt

it seems to solve this simple example

but in practice there a lot of call to processLine using arguments to build the command

InterfaceForChoiceOfDeconvFiles.C:	gROOT->ProcessLine(Form(".! cp %s/%s  %s/FORDECONVOLUTION/%s_%s", this->l_AnalysisRepertory.Data(),  ListOfNameFiles[i].Data(), this->l_AnalysisRepertory.Data(), this->l_typeofTree.Data(), ListOfNameFiles[i].Data()));
InterfaceForChoiceOfDeconvFiles.C:  gROOT->ProcessLine(Form(".! cp %s/%s  %s/FORDECONVOLUTION/%sMini_%s", this->l_AnalysisRepertory.Data(),  (char*) ListOfNameFiles[FirstFile], this->l_AnalysisRepertory.Data(), this->l_typeofTree.Data(), (char*) ListOfNameFiles[FirstFile]));
InterfaceForChoiceOfDeconvFiles.C:  gROOT->ProcessLine(Form(".! cp %s/%s  %s/FORDECONVOLUTION/%sMaxi_%s", this->l_AnalysisRepertory.Data(), (char*) ListOfNameFiles[SecondFile], this->l_AnalysisRepertory.Data(), this->l_typeofTree.Data(), (char*) ListOfNameFiles[SecondFile]));
InterfaceForChoiceOfDeconvFiles.C:	gROOT->ProcessLine(Form(".! cp %s/%s  %s/FORDECONVOLUTION/%sMini_%s",  this->l_AnalysisRepertory.Data(), (char*) ListOfNameFiles[PosInSideTheList-1], this->l_AnalysisRepertory.Data(), this->l_typeofTree.Data(), (char*) ListOfNameFiles[PosInSideTheList-1]));
InterfaceForChoiceOfDeconvFiles.C:	gROOT->ProcessLine(Form(".! cp %s/%s  %s/FORDECONVOLUTION/%sMaxi_%s",  this->l_AnalysisRepertory.Data(), (char*) ListOfNameFiles[PosInSideTheList-1], this->l_AnalysisRepertory.Data(), this->l_typeofTree.Data(), (char*) ListOfNameFiles[PosInSideTheList-1]));
InterfaceForChoiceOfDeconvFiles.C:  gROOT->ProcessLine(".L  CheckDeconvFiles3.C");
InterfaceForDeconvolution.C:  gROOT->ProcessLine(Form(".! rm %s/tmpfiles.txt", this->l_AnalysisRepertory.Data()));
InterfaceForDeconvolution.C:    gROOT->ProcessLine(Form(".! ls %s/FORDECONVOLUTION/*.ibu > %s/tmpfiles.txt", this->l_AnalysisRepertory.Data(), this->l_AnalysisRepertory.Data() ));
InterfaceForDeconvolution.C:    gROOT->ProcessLine(Form(".! ls %s/FORDECONVOLUTION/*.dat > %s/tmpfiles.txt", this->l_AnalysisRepertory.Data(), this->l_AnalysisRepertory.Data() ));
InterfaceForDeconvolution.C:    gROOT->ProcessLine(Form(".! mv '%s/%s' '%s/%s'", this->l_CodeRepertory.Data(), "NewDSFile.txt", (char *) (k_DirWhereAreFCResults+"/../$inp/def_spec"), fNewNameForDS->GetText())); 
InterfaceForDeconvolution.C:    gROOT->ProcessLine(Form(".! mv '%s/%s' '%s/%s'", this->l_CodeRepertory.Data(), "NewDSFile.txt", (char *) (k_DirWhereAreMCResults+"/../$inp/def_spec"), fNewNameForDS->GetText())); 
InterfaceForDeconvolution.C:      gROOT->ProcessLine(Form(".! cp %s/ListeGraphInterpolForDS_%s.txt %s/ListeGraphInterpolForDS_%s.txt", this->l_AnalysisRepertory.Data(), NameOfDS.Data(), this->l_AnalysisRepertory.Data(), NameOutputDS.Data()));
InterfaceForDeconvolution.C://ThV20181030	gROOT->ProcessLine(Form(".! cp '%s' '%s/%s'", fi.fFilename, this->l_CodeRepertory.Data(), (char *) (k_DirWhereAreFCResults+"/../$inp/response/."))); 
InterfaceForDeconvolution.C:	gROOT->ProcessLine(Form(".! cp '%s' '%s'", fi.fFilename,  (char *) (k_DirWhereAreFCResults+"/../$inp/response/."))); 
InterfaceForDeconvolution.C:// ThV20170328	gROOT->ProcessLine(Form(".! cp '%s' '%s/%s'", fi.fFilename, this->l_CodeRepertory.Data(), (char *) (k_DirWhereAreMCResults+"/../$inp/response/."))); 
InterfaceForDeconvolution.C:	gROOT->ProcessLine(Form(".! cp '%s' '%s'", fi.fFilename,  (char *) (k_DirWhereAreMCResults+"/../$inp/response/."))); 
InterfaceForDeconvolution.C:	gROOT->ProcessLine(Form(".! cp '%s' '%s'", fi.fFilename, (char *) (k_DirWhereAreFCResults+"/../$inp/def_spec/."))); 
InterfaceForDeconvolution.C:	gROOT->ProcessLine(Form(".! cp '%s' '%s'", fi.fFilename, (char *) (k_DirWhereAreMCResults+"/../$inp/def_spec/."))); 
InterfaceForDeconvolution.C:	gROOT->ProcessLine(Form(".! ls %s/FORDECONVOLUTION/*.dat | grep %s > %s/tmpfiles.txt", this->l_AnalysisRepertory.Data(), a_DataType, this->l_AnalysisRepertory.Data()));
InterfaceForDeconvolution.C://	gROOT->ProcessLine(Form(".! ../'$'bin/%s file.inp", this->l_ExecutableChosen.Data())); ThV 2010323 passage en chemin absolu
InterfaceForDeconvolution.C:	gROOT->ProcessLine(Form(".! /TMPLOCAL/ILAIM/JOB1.0/V33U_M_G/MC/'$'bin/%s file.inp", this->l_ExecutableChosen.Data()));
InterfaceForDeconvolution.C:	gROOT->ProcessLine(Form(".! /TMPLOCAL/ILAIM/JOB1.0/V33U_M_G/FC/'$'bin/%s file.inp", this->l_ExecutableChosen.Data()));
InterfaceForDeconvolution.C:	  //gROOT->ProcessLine(Form(".! ../'$'bin/%s ../IQU_runTotal.inp", k_MCIQUFORANA_EXE)) ;ThV 2010323 passage en chemin absolu
InterfaceForDeconvolution.C:          gROOT->ProcessLine(Form(".! /TMPLOCAL/ILAIM/JOB1.0/V33U_M_G/MC/'$'bin/%s ../IQU_runTotal.inp", k_MCIQUFORANA_EXE));
InterfaceForDeconvolution.C:	  //gROOT->ProcessLine(Form(".! ../'$'bin/%s ../IQU_runTotal.inp", k_FCIQUFORANA_EXE)) ;ThV 2010323 passage en chemin absolu
InterfaceForDeconvolution.C:	  gROOT->ProcessLine(Form(".! /TMPLOCAL/ILAIM/JOB1.0/V33U_M_G/FC/'$'bin/%s ../IQU_runTotal.inp", k_FCIQUFORANA_EXE));
InterfaceForDeconvolution.C:      gROOT->ProcessLine(".! rm output33.*");
InterfaceForDeconvolution.C:  gROOT->ProcessLine(Form(".! ls %s/*.plo > tmplistofPloFiles.txt", this->l_WhereStoreFiles.Data()));
InterfaceForDeconvolution.C:  gROOT->ProcessLine(".!rm -f tmplistofPloFiles.txt");
InterfaceForDeconvolution.C:    gROOT->ProcessLine(Form(".! '%s' %s", (char*) k_OLDPLOT_EXE, "file.plo"));
InterfaceForDeconvolution.C:    gROOT->ProcessLine(".! rm -f file.plo");
InterfaceForDeconvolution.C:     //gROOT->ProcessLine(Form(".! '%s' %s", (char*) k_NEWPLOT_EXE, "file.plo"));
InterfaceForDeconvolution.C:     gROOT->ProcessLine(".! rm -f file.plo");
InterfaceForDeconvolution.C~:  gROOT->ProcessLine(Form(".! rm %s/tmpfiles.txt", this->l_AnalysisRepertory.Data()));
InterfaceForDeconvolution.C~:    gROOT->ProcessLine(Form(".! ls %s/FORDECONVOLUTION/*.ibu > %s/tmpfiles.txt", this->l_AnalysisRepertory.Data(), this->l_AnalysisRepertory.Data() ));
InterfaceForDeconvolution.C~:    gROOT->ProcessLine(Form(".! ls %s/FORDECONVOLUTION/*.dat > %s/tmpfiles.txt", this->l_AnalysisRepertory.Data(), this->l_AnalysisRepertory.Data() ));
InterfaceForDeconvolution.C~:    gROOT->ProcessLine(Form(".! mv '%s/%s' '%s/%s'", this->l_CodeRepertory.Data(), "NewDSFile.txt", (char *) (k_DirWhereAreFCResults+"/../$inp/def_spec"), fNewNameForDS->GetText())); 
InterfaceForDeconvolution.C~:    gROOT->ProcessLine(Form(".! mv '%s/%s' '%s/%s'", this->l_CodeRepertory.Data(), "NewDSFile.txt", (char *) (k_DirWhereAreMCResults+"/../$inp/def_spec"), fNewNameForDS->GetText())); 
InterfaceForDeconvolution.C~:      gROOT->ProcessLine(Form(".! cp %s/ListeGraphInterpolForDS_%s.txt %s/ListeGraphInterpolForDS_%s.txt", this->l_AnalysisRepertory.Data(), NameOfDS.Data(), this->l_AnalysisRepertory.Data(), NameOutputDS.Data()));
InterfaceForDeconvolution.C~:	gROOT->ProcessLine(Form(".! cp '%s' '%s/%s'", fi.fFilename, this->l_CodeRepertory.Data(), (char *) (k_DirWhereAreFCResults+"/../$inp/response/."))); 
InterfaceForDeconvolution.C~:	gROOT->ProcessLine(Form(".! cp '%s' '%s/%s'", fi.fFilename, this->l_CodeRepertory.Data(), (char *) (k_DirWhereAreMCResults+"/../$inp/response/."))); 
InterfaceForDeconvolution.C~:	gROOT->ProcessLine(Form(".! cp '%s' '%s'", fi.fFilename, (char *) (k_DirWhereAreFCResults+"/../$inp/def_spec/."))); 
InterfaceForDeconvolution.C~:	gROOT->ProcessLine(Form(".! cp '%s' '%s'", fi.fFilename, (char *) (k_DirWhereAreMCResults+"/../$inp/def_spec/."))); 
InterfaceForDeconvolution.C~:    gROOT->ProcessLine(Form(".! ls %s/FORDECONVOLUTION/*.dat | grep %s > %s/tmpfiles.txt", this->l_AnalysisRepertory.Data(), a_DataType, this->l_AnalysisRepertory.Data() ));
InterfaceForDeconvolution.C~:	gROOT->ProcessLine(Form(".! ../'$'bin/%s file.inp", this->l_ExecutableChosen.Data()));
InterfaceForDeconvolution.C~:	  gROOT->ProcessLine(Form(".! ../'$'bin/%s ../IQU_runTotal.inp", k_MCIQUFORANA_EXE));
InterfaceForDeconvolution.C~:	  gROOT->ProcessLine(Form(".! ../'$'bin/%s ../IQU_runTotal.inp", k_FCIQUFORANA_EXE));
InterfaceForDeconvolution.C~:      gROOT->ProcessLine(".! rm output.*");
InterfaceForDeconvolution.C~:  gROOT->ProcessLine(Form(".! ls %s/*.plo > tmplistofPloFiles.txt", this->l_WhereStoreFiles.Data()));
InterfaceForDeconvolution.C~:  gROOT->ProcessLine(".!rm -f tmplistofPloFiles.txt");
InterfaceForDeconvolution.C~:    gROOT->ProcessLine(Form(".! '%s' %s", (char*) k_OLDPLOT_EXE, "file.plo"));
InterfaceForDeconvolution.C~:    gROOT->ProcessLine(".! rm -f file.plo");
InterfaceForDeconvolution.C~:    gROOT->ProcessLine(Form(".! '%s' %s", (char*) k_NEWPLOT_EXE, "file.plo"));
InterfaceForDeconvolution.C~:    gROOT->ProcessLine(".! rm -f file.plo");
InterfaceReadData.C:    gROOT->ProcessLine(Form(".! rm -f %s", FileToCreate.Data()));
grep: OLD : Is a directory
grep: OLD2: Is a directory
PrepareFilesForDeconvolution.C:    gROOT->ProcessLine(Form(".! rm -f %s/ListOfFilesDeconv.txt", a_AnalysisRepertory));
PrepareFilesForDeconvolution.C:      		if(IdDiscri == 1 && IdE == 1)  gROOT->ProcessLine(Form(".! cp %s/%s  %s/FORDECONVOLUTION/%sMedianDeconv.dat", a_AnalysisRepertory, NameOfDeconvFile, a_AnalysisRepertory, a_typeofTree));
PrepareFilesForDeconvolution.C:    gROOT->ProcessLine(Form(".! rm -f %s/ListOfFilesDeconv.txt", a_AnalysisRepertory));
PrepareFilesForDeconvolution.C:      if(Z == 1 && IdE == 1)  gROOT->ProcessLine(Form(".! cp %s/%s  %s/FORDECONVOLUTION/%sMedianDeconv.dat",  a_AnalysisRepertory, NameOfDeconvFile, a_AnalysisRepertory, a_typeofTree));
PrepareFilesForDeconvolution.C~:    gROOT->ProcessLine(Form(".! rm -f %s/ListOfFilesDeconv.txt", a_AnalysisRepertory));
PrepareFilesForDeconvolution.C~:      if(IdDiscri == 1 && IdE == 1)  gROOT->ProcessLine(Form(".! cp %s/%s  %s/FORDECONVOLUTION/%sMedianDeconv.dat", a_AnalysisRepertory, NameOfDeconvFile, a_AnalysisRepertory, a_typeofTree));
PrepareFilesForDeconvolution.C~:    gROOT->ProcessLine(Form(".! rm -f %s/ListOfFilesDeconv.txt", a_AnalysisRepertory));
PrepareFilesForDeconvolution.C~:      if(Z == 1 && IdE == 1)  gROOT->ProcessLine(Form(".! cp %s/%s  %s/FORDECONVOLUTION/%sMedianDeconv.dat",  a_AnalysisRepertory, NameOfDeconvFile, a_AnalysisRepertory, a_typeofTree));
ReadDataAcqu2.C:  gROOT->ProcessLine(Form(".! rm -f %s", namefileroot.Data())); 
ReadDataAcqu2.C:  gROOT->ProcessLine(Form(".! echo `wc -l '%s' | awk '{print $1} ' ` > tmpNlinesTot.tx", a_filename));
ReadDataAcqu2.C:  gROOT->ProcessLine(".! rm -f tmpNlinesTot.tx");
ReadDataAcqu2.C~:  gROOT->ProcessLine(Form(".! rm -f %s", namefileroot.Data())); 
ReadDataAcqu2.C~:  gROOT->ProcessLine(Form(".! echo `wc -l '%s' | awk '{print $1} ' ` > tmpNlinesTot.tx", a_filename));
ReadDataAcqu2.C~:  gROOT->ProcessLine(".! rm -f tmpNlinesTot.tx");
Binary file ReadDataAcqu2_C.dll matches
Binary file ReadDataAcqu2_C.so matches
ReadDataAcqu2_Windows.C:  gROOT->ProcessLine(Form(".! rm -f %s", namefileroot.Data())); 
ReadDataAcqu2_Windows.C:  gROOT->ProcessLine(Form(".! echo `wc -l '%s' | awk '{print $1} ' ` > tmpNlinesTot.tx", a_filename));
ReadDataAcqu2_Windows.C:  gROOT->ProcessLine(".! rm -f tmpNlinesTot.tx");
ReadDataAcquNumBC.C:  	gROOT->ProcessLine(Form(".! rm -f %s", namefileroot.Data())); 
ReadDataAcquNumBC.C:  	gROOT->ProcessLine(Form(".! echo `wc -l '%s' | awk '{print $1} ' ` > tmpNlinesTot.tx", a_filename));
ReadDataAcquNumBC.C:  	gROOT->ProcessLine(".! rm -f tmpNlinesTot.tx");
Binary file ReadDataAcquNumBC_C.so matches
ReadDataAcquNumBC_csv2.C:  	gROOT->ProcessLine(Form(".! rm -f %s", namefileroot.Data())); 
ReadDataAcquNumBC_csv2.C:	gROOT->ProcessLine(Form(".! echo `wc -l %s | awk '{print $1} ' ` > tmpNlinesTot.tx", a_filename));
ReadDataAcquNumBC_csv2.C:	gROOT->ProcessLine(".! rm -f tmpNlinesTot.tx");
Binary file ReadDataAcquNumBC_csv2_C.so matches
ReadDataAcquNumBC_csv2_cTV.C:  	gROOT->ProcessLine(Form(".! rm -f %s", namefileroot.Data())); 
ReadDataAcquNumBC_csv2_cTV.C:	gROOT->ProcessLine(Form(".! echo `wc -l %s | awk '{print $1} ' ` > tmpNlinesTot.tx", a_filename));
ReadDataAcquNumBC_csv2_cTV.C:	gROOT->ProcessLine(".! rm -f tmpNlinesTot.tx");

so can this solution be generalized to all the cases?

Sure, you can still use Form to construct the command and then run the command through system. (or better yet TString::Format as @pcanal says below).

EDIT:
the fact that system works (while ProcessLine(".! ...") doesn’t) likely points to a bug in ProcessLine, but it should still be verified that the bug is present in ROOT 6 as ROOT 5 is not supported anymore.

Note: Do not use ::Form, it return a static buffer and is unstable (as in if anything under the call function(Form(..) also calls Form the buffer will be modified. Use TString::Format instead.

Also you want “C++” alternative to a lot of those calls:

  • TSystem::Unlink for rm
  • TFile::Cp or TSystem::CopyFile for cp
  • TSystem::OpenDirectory and TSystem::GetDirEntry instead of ls and scanning the result.

I would guess than most likely than not the wc calls are also 'surperfluous` (i.e. I would guess that the code that use the results has other way to get that information).

If it’s just counting lines: How to count lines of a file in C++? - Stack Overflow

You have to note that the Pb occurs only if the root program is lanched trough a shell including a “su ilaim_u” command .
Il I lanched the root program trough my user account I don’t get the Pb
But We need the " su iliam " command to avoid right conflicts on file created by the application…

if fear that this pb could be hiding a more general one concerning using root through a su command…
but we need that to be bale to use our application based on root/C++ without right conflict…
Any idea about using root after a su command could affect its behaviour ( Pb of root installation? what can checked ?)
Regards
Thibaut

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.