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));
gROOT->ProcessLine(".q");
}

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: =========
/lib/libc.so.6[0x60a6f18]
/lib/libc.so.6(__libc_free+0x79)[0x60aa41d]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x744bfe1]
/usr/lib/libstdc++.so.6(_ZNSs4_Rep10_M_destroyERKSaIcE+0x1d)[0x74276cd]
/usr/local/bin/root/lib/libCint.so(_ZNSt8_Rb_treeISsSsSt9_IdentityISsESt4lessISsESaISsEE8_M_eraseEPSt13_Rb_tree_nodeISsE+0x6a)[0x15f7e0]
/usr/local/bin/root/lib/libCint.so(_ZNSt8_Rb_treeISsSsSt9_IdentityISsESt4lessISsESaISsEE8_M_eraseEPSt13_Rb_tree_nodeISsE+0x2d)[0x15f7a3]
/usr/local/bin/root/lib/libCint.so[0x15e59a]

There are many more lines then this comes:

======= Memory map: ========
00111000-00113000 r-xp 00000000 fd:00 3438304 /lib/libdl-2.4.so
00113000-00114000 r–p 00001000 fd:00 3438304 /lib/libdl-2.4.so
00114000-00115000 rw-p 00002000 fd:00 3438304 /lib/libdl-2.4.so
00115000-0011e000 r-xp 00000000 fd:00 3437321 /lib/libnss_files-2.4.so
0011e000-0011f000 r–p 00008000 fd:00 3437321 /lib/libnss_files-2.4.so
0011f000-00120000 rw-p 00009000 fd:00 3437321 /lib/libnss_files-2.4.so
00120000-00122000 r-xp 00000000 fd:00 4271953 /usr/lib/libXau.so.6.0.0
00122000-00123000 rw-p 00001000 fd:00 4271953 /usr/lib/libXau.so.6.0.0
00123000-00323000 r-xp 00000000 fd:00 12611896 /usr/local/bin/root/lib/libCint.so
00323000-00327000 rw-p 00200000 fd:00 12611896 /usr/local/bin/root/lib/libCint.so
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:

Cheers,
Philippe

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

Eddy

To execute any shell command from the ROOT-based C/ C++application one can apply root.cern.ch/root/htmldoc/TSyste … 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
TEM(3)

NAME
system - execute a shell command

SYNOPSIS
#include
int system(const char *string);

DESCRIPTION
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