How can I output commands from a bash script to another shell (python, root)?

I want to open a shell from another program from a bash script (especially root is a physics program) and execute several commands in a row.

I know to enter one command:

echo ".L mymacro.C" | root -l  

      

but I need to enter several commands one after the other without closing the root shell (root is not the root user, but an interactive shell for another program)

I tried with parentheses, but that failed:

(echo ".L mymacro.C"; echo "myClass a";echo "a.Loop") | root -l

      

I need these 3 commands injected into the root shell one by one:

mymacro.C
myClass a
a.Loop

      

How can I do this from a bash script?

Many thanks.

+3


source to share


4 answers


Maybe here's the doc might work:



$ root -l <<EOF
.L mymacro.C
myClass a
a.Loop
EOF

      

+3


source


Can't you just:

echo -e ".L mymacro.C\nmyClass a\na.Loop" | root -l

      

This will send the data line by line to the root shell.



Or, if you really want to do it one by one, you can always loop like this:

Code removed thanks to mhawke's note

+1


source


It looks like you need to attach curly braces. Try it like this:

cat <<'EOF' | root -l
{
.L mymacro.C
myClass a
a.Loop
}
EOF

      

0


source


thanks for the answers, but unfortunately none of them worked for me. What was created to create another file run.cxx

with:

{
gROOT->ProcessLine(".L AnalyseSimple.C");
AnalyseSimple a;
a.Loop();
gROOT->ProcessLine(".q");
}

      

and add root -l run.cxx

to bash script

0


source







All Articles