Using ProcessLine() to run a bash command in a C script

I have a written a c-file (gainMatch.C) that is executed in root and creates a linux directory
my code is:

gainMatch(char *filename) {
gROOT->ProcessLine(strcat(".! mkdir /home/work/", filename));

I execute the c function by:

.x gainMatch.C(“run8310”)
Root sucessfully runs the code creating a folder /home/work/run8310. However, when I exit ROOT I am flooded with a long line of errors. I have listed the first 10 lines of errors below:

*** glibc detected *** /usr/local/bin/root/bin/root.exe: free(): invalid next size (fast): 0x0ad5b240 ***
======= Backtrace: =========

There are many more lines then this comes:

======= Memory map: ========
00111000-00113000 r-xp 00000000 fd:00 3438304 /lib/
00113000-00114000 r–p 00001000 fd:00 3438304 /lib/
00114000-00115000 rw-p 00002000 fd:00 3438304 /lib/
00115000-0011e000 r-xp 00000000 fd:00 3437321 /lib/
0011e000-0011f000 r–p 00008000 fd:00 3437321 /lib/
0011f000-00120000 rw-p 00009000 fd:00 3437321 /lib/
00120000-00122000 r-xp 00000000 fd:00 4271953 /usr/lib/
00122000-00123000 rw-p 00001000 fd:00 4271953 /usr/lib/
00123000-00323000 r-xp 00000000 fd:00 12611896 /usr/local/bin/root/lib/
00323000-00327000 rw-p 00200000 fd:00 12611896 /usr/local/bin/root/lib/
00327000-00475000 rw-p 00327000 00:00 0

Which is followed by many more lines of error.
Can anyone help me?

strcat(".! mkdir /home/work/", filename)You are asking for the compiler to append to a const string!. Instead use:


Thank you so much. It now works perfectly.

Many of these commands are available in TSystem .
In your case have a look at TSystem::mkdir


To execute any shell command from the ROOT-based C/ C++application one can apply … ystem:Exec
on any platform, like this gSystem->Exec("echo my favorite shell command");However on almost all platforms, the “vanilla” C subroutine “system” will do the job as well[code]man system

SYSTEM(3) Linux Programmers Manual SYS

system - execute a shell command

int system(const char *string);

system() executes a command specified in string by calling /bin/sh -c
string, and returns after the command has been completed. During exe-
cution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT
will be ignored.[/code]See: $ROOTSYS/tutorials/rootalias.C for futher information