# Headless

**URL:** <https://root-forum.cern.ch/t/headless/15132>\
**Category:** ROOT\
**Created:** [October 23, 2012, 10:21pm UTC](https://root-forum.cern.ch/t/headless/15132 "2012-10-23T22:21:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tjstavenger](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/e274bd/32.png) [@tjstavenger](https://root-forum.cern.ch/u/tjstavenger)\
**Post date:** [October 23, 2012, 10:21pm UTC](https://root-forum.cern.ch/t/headless/15132/1 "2012-10-23T22:21:04Z")

</div>

Is there a way to run ROOT in a “headless” mode? For example, could I run an instance of a ROOT script or application from a command line, have it generate graphical features (like a histogram) and print/save it to a file all without requiring or displaying a UI?

I’ve searched for “headless” in the ROOT documentation and here on the forum, but I haven’t found anything yet.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 23, 2012, 10:31pm UTC](https://root-forum.cern.ch/t/headless/15132/2 "2012-10-23T22:31:22Z")

</div>

Google for “ROOT batch mode”.  
Try:  
root -?  
man root  
See also [url][Compile and run from command prompt](https://root-forum.cern.ch/t/compile-and-run-from-command-prompt/13799/2) and [url][Compile a macro without running?](https://root-forum.cern.ch/t/compile-a-macro-without-running/14759/1)

---

<div class="post-metadata">

**Author:** ![tjstavenger](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/e274bd/32.png) [@tjstavenger](https://root-forum.cern.ch/u/tjstavenger)\
**Post date:** [October 30, 2012, 10:06pm UTC](https://root-forum.cern.ch/t/headless/15132/3 "2012-10-30T22:06:27Z")

</div>

Wile E. Coyote – Thanks for the suggestion.

I tried using SetBatch(true), and while it didn’t paint the UI it also didn’t do any UI operations at all. So when I instructed ROOT to draw a histogram to a batch mode canvas and then save it, presumably the histogram was never drawn as the file was never saved.

What I’m looking for is something in between – a headless mode where the UI operations happen, but aren’t painted to a screen. That way I can draw and save a histogram to an image without ever displaying the canvas.

Does that make sense and is it possible in ROOT?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 30, 2012, 10:23pm UTC](https://root-forum.cern.ch/t/headless/15132/4 "2012-10-30T22:23:02Z")

</div>

Try to execute: `root -b -l -q trial.cxx
root -b -l -q trial.cxx++` using the following “trial.cxx”: [code]#include “TH1.h”  
#include “TCanvas.h”  
#include “TPad.h”

void trial(void)  
{  
TH1F \*h1 = new TH1F(“h1”, “histo from a gaussian”, 100, -3, 3);  
h1-\>FillRandom(“gaus”, 10000);  
TCanvas \*c1 = new TCanvas(“c1”, “c1”);  
h1-\>Draw();  
gPad-\>Modified(); gPad-\>Update(); // just a precaution  
c1-\>SaveAs(“c1.pdf”);  
}[/code]

---

<div class="post-metadata">

**Author:** ![tjstavenger](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/e274bd/32.png) [@tjstavenger](https://root-forum.cern.ch/u/tjstavenger)\
**Post date:** [October 30, 2012, 10:47pm UTC](https://root-forum.cern.ch/t/headless/15132/5 "2012-10-30T22:47:09Z")

</div>

Ah, I found where I went wrong – at least it appears to be working now.

I had created a new canvas and then called SetBatch(true) on it, which didn’t work well. If I call gROOT-\>SetBatch(true) before creating the canvas and gROOT-\>SetBatch(false) after drawing & saving, the file is created without a window appearing. Hopefully there aren’t ramifications to turning on & off batch mode like this.

Thanks for the help!
