Run a root script from CMD

Hello guys,

I’m following this:

which states in an example that to pass a string as a parameter you’re supposed to do:

root -b -q 'myMacro.C("text")' > myMacro.log

I have a root script with two string arguments writeHVDataPlots(const string data_location, const string data_timestamp) which plots and writes TGraphs in a Root file. I’m trying to run it from command prompt:

root -q 'writeHVDataPlots.C("\\\Users\User\data\", "data_from_sometime_to_sometime")'

I get the error:

Warning in <TApplication::GetOptions>: macro 'writeHVDataPlots.C not found

Notice how the second ' is not there on the error. I even tried the complete path of the script but still same error.

PS 1: I’m running on Windows 10.
PS 2: Script works perfectly fine when I do it through root.

Thanks in advance for any help

You may need to use more escape characters for all the backslashes. Try to create a macro that just prints the argument, and call ROOT with that macro, then make sure that the escaping is correct. I don’t use Windows, but maybe using

root -q 'writeHVDataPlots.C("\\\\Users\\User\\data\\", "data_from_sometime_to_sometime")'

might work for you.

That was a good call, but sadly same error =/

It looks like ROOT thinks ' is part of the name of the macro.
With some clever usage of double quotes and escaping I think you can make things work with just double quotes. If that works, this might be a bug report for ROOT’s command line parsing logic.

First of all, to clarify, I’ve made a mistake in the first place. For a root script to run in Windows it would need the path in slashes and not in backslashes as in Windows paths or else it gives an error. It’s really weird but since it works, that’s fine.

However, I repeated all the steps and the problem persists so I’ve tried it with other scrips of mine and it works fine without a parameter. When I try to pass a string inside, as @eguiraud has noted, it again seems as if ROOT reads the first ' as part of the macro. I tried to use escaping of some sort but couldn’t get it to work.

Is there a way around this? Any other clue here?


Single quote is not supported in the command prompt on Windows. Try to only use double quotes

Cheers, Bertrand.