Running scripts without interface

Hi Francois,

We recently installed a powerful computer cluster at the McGovern Institute. I want to use the cluster to run Brainstorm scripts, however it does not support an interactive interface, thus I cannot use the Brainstorm main window to define a current project etc.

My script (created from the process window, after clicking 'run', select the processes, then save the .m file) does not explicitly define the active project. Is there a way through script commands to explicitly define the current project and then run my script? Any help is highly appreciated!

Thank you,

Hi Dimitrios,

I will need to work at some point on producing a Java-free and interface-free version of Matlab, to run on distant servers.
For now, there is no way to start Brainstorm without Java (matlab -nojvm), but there are ways to run Brainstorm scripts that are not producing any interactive output.

For clean ways to create/delete protocols without interactions, you can look at all the scripts for corresponding to the tutorials, I updated them very recently (brainstorm3/toolbox/script/tutorial_*.m).

For changing the current protocol:

% Get protocol index
iProtocol = bst_get('Protocol', ProtocolName);
% Set as current protocol
gui_brainstorm('SetCurrentProtocol', iProtocol);

Is this what you needed?


Hi Francois,

Thank you. I have more question. I would like to run multiple brainstorm scripts at the same time. When I open 2 Matlabs and brainstorms, I get a warning in the second instance:
" Warning: Brainstorm is already running from a different Matlab session."

Can I run different scripts in 2 Matlabs, or will there be a conflict regarding which is the current protocol, current subject, etc?

Thank you,

The current protocol and the definition of the entire database is defined for each user, and saved in ~/.brainstorm/brainstorm.mat.
Multiple instances of Matlab running Brainstorm, started from the same user on the same computer, would compete in accessing this same file. There is no system to handle concurrent accesses in Brainstorm, the they would overwrite the same file, producing unpredictable results.
So no, you cannot easily run multiple instances of Brainstorm.

Two options:

  1. You start two Matlab instances from different users on the same machine: then if the two users are not working on the same protocols at the same time, there is no problem.
  2. You start two Matlab instances from the same user: this works if you do not change the current protocol, if you don’t work on the same folders at the same time, and if you enforce the reloading of the protocol in instance #2 after you close instance #1.


Now, could it possible to start Brainstorm without interface?

“brainstorm nogui” starts the interface but hides it.
“brainstorm server” is designed to run on headless servers (computation clusters with no screen attached)

FYI: Brainstorm now supports the direct execution of custom Matlab scripts, including from the compiled version of Matlab, including all the SPM and FieldTrip dependencies. This means that you can write your own .m scripts and execute them on a computation cluster on which you don't have a Matlab license but only the MCR installer.

1 Like

Is there a way to get the name of the current protocol from the command line without running it or setting it again when it is already loaded?

I am writing test function for my pipeline
I have a small test protocol
I would like to have something like that

ProtocolName = 'Test'
if ~brainstorm('status')
    brainstorm nogui
    iProtocol = bst_get('Protocol', ProtocolName)
    gui_brainstorm('SetCurrentProtocol', iProtocol);
elseif Protocolname ~= bst_getcurrentProtocolName()
    Protocol = bst_get('Protocol', ProtocolName)
gui_brainstorm('SetCurrentProtocol', iProtocol);

bst_getcurrentProtocolName is something that I am looking for

ProtocolInfo = bst_get('ProtocolInfo');

Two comments:

  • testing the equality of two char arrays is done with strcmp, not ~=
  • this would crash because of unkown variable iProtocol => delete the last line, you don't need to set again the current protocol

Thanks! This was what I needed!

ProtocolInfo = bst_get('ProtocolInfo');