How to determine/change Root session working directory on Windows

I have Root 5.23/04 (22 Apr 2009) running on my Windows Vista64 laptop as a desktop icon. When I click on the desktop Root icon, a Root session pops up. In this instantiation .! pwd fails by saying “‘pwd’ is not recognized as an internal or external command, operable program or batch file.”

I can also get into Root from a Cygwin window >root and at the following root prompt the following occurs:

root [0] .! pwd
root [1] .! cd bin
The system cannot find the path specified

(there really is a directory /home/root/bin so it should have gone into that bin directory)

So if ‘pwd’ is recognized in my Cygwin launched Root session but NOT in my desktop Root icon launched Root session, I am ok never using the desktop Root icon as a launch and from now on i will enter via Cygwin only. Ok fine.

But still the ‘cd’ command failed.

How do I control what directory on my Windows machine is the directory the Root session considers to be its “.” directory?

I would like to maintain any number of separate folders in Windows, where I will keep a small number of project specific files, like *.C code, and whatever the Root equivalent of the PAW *.kumac files are.

So in a familiar world I should simply be able to do something like this:

root [0] .! pwd
root [1] .! cd project1
root [2] .L macro.C
root [3] macro();

So if there is an object creation sequence which can render this ‘.! cd xyz’ command operable to get into my xyz directory where macro.C lives and into which the input and output files should be active, please let me know

Alternatively, I could perhaps just add my xyz dir to my path. I see from executing a macro which I know does not exist an error msg which tells me what my path is now: .;c:\root/macros;

So there are two directories currently in my path, the “.” directory and the c:\root/macros directory. I do not know where the rootrc file lives in the c:\root\ tree (standard installation, I did not change anything under there) so I don’t know where this is set and hence where I can change how the default path is set.

If someone could let me know either how to make ‘cd’ function as expected, or let me know how to add xyz dir to my path, I would greatly appreciate the input and the learning experience



gSystem->pwd(); and gSystem->cd("anyDirectory");
See TSystem::cd() or TSystem::ChangeDirectory() and TSystem::pwd()

Cheers, Bertrand.

Unfortunately, I cut and pasted each command you suggested into my virgin ROOT 5.23/04 session launched from the Desktop icon, and neither succeeded. Am I to define some objects first and then do these commands, or are these commands expected to deliver the pwd and cd right off the bat?

I need to see the result of pwd before I know the syntax that the cd command is going to want to possess as argument. I mean once pwd delivers, then I can see how the Root session sees my disk tree (whether C: is included, whether Cygwin is included in the path string as it is if I launch Root from a Cygwin window etc…)

Can you possibly elaborate further? If there is a sequence of several object creation steps please list them all from a the point of view of a virgin launch of Root from the desktop icon if you could.

Thank you very much for your time and consideration


OK, my bad. Don’t put the semicolon at the end of gSystem->pwd(), or use cout << gSystem->pwd():

C:\Users\bellenot>root -l root [0] gSystem->pwd() (const char* 0x3fe4a8)"C:\\Users\\bellenot" root [1] cout << gSystem->pwd(); C:\Users\bellenot root [2] gSystem->cd("rootdev"); root [3] gSystem->pwd() (const char* 0x2832f68)"C:\\Users\\bellenot\\rootdev" root [4] cout << gSystem->pwd(); C:\Users\bellenot\rootdev root [5]
See also this screenshot:

Cheers, Bertrand.

Thank you very much!
This totally works in my Desktop icon launched 5.23/04 Root session

I have only one mysterious behaviour different from yours but it is very minor. Namely, when I perform the cout << pwd command, it delivers the directory on the next line ok but the next prompt “root [6]” appears on the same line as the cout output. Perhaps there is some sort of “carriage return” that your system enjoys and my system lacks. IN any event, this is a very minor difference between yours and my system behaviour

Thank you very much as I did not really know enough at this stage to navigate this (new to me) C++ syntax for Root. I am very appreciative of your taking the time to explain and help. Much appreciated.

  *                                         *
  *        W E L C O M E  to  R O O T       *
  *                                         *
  *   Version   5.23/04     22 April 2009   *
  *                                         *
  *  You are welcome to visit our Web site  *
  *            *
  *                                         *

ROOT 5.23/04 (trunk@28330, Apr 23 2009, 07:41:00 on win32)

CINT/ROOT C/C++ Interpreter version 5.17.00, Dec 21, 2008
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] gSystem->pwd()
(const char* 0x28588)"C:\\root"
root [1] cout << gSystem->pwd();
C:\rootroot [2]
root [2]
root [2]
root [2] gSystem->cd("sandbox");
root [3] gSystem->pwd()
(const char* 0x3bdb380)"C:\\root\\sandbox"
root [4] cout << gSystem->pwd();
C:\root\scout << gSystem->pwd();
C:\root\sandboxroot [6]
root [6]
root [6]
root [6]
root [6]
root [6] cout << gSystem->pwd();
C:\root\sandboxroot [7]
root [7]
root [7] cout << gSystem->pwd() ;
C:\root\sandboxroot [8]


You’re very welcome! And the difference you see is most probably due to some changes in ROOT (since 2009, changes have been made… :wink:)

Cheers, Bertrand.