Page 1 of 1

Reading Configuration Files

Posted: 05 Mar 2010, 11:21
by timo.veldt
I'm working on a BCI2000 application (3rd filter for the operator) that controls an external piece of hardware to present stimuli. The module for this external hardware has been tried and tested and it works.

The module allows the user to specify certain parameters in a text file, which I would like to read in with my BCI2000 Application. When trying to read this config file (stored in the same directory as the executable) an error message is presented that tells me the file cannot be found.

After some testing I found the problem, which has to do with the current working directory.

Ingredients:
- BCI2000 v3.0
- Operator
- gUSBampSource
- DummySignalProcessing
- CustomStimulusPresentation (derived from ApplicationBase (because StimulusPresentationTask already defined too many parameters))

When running the program and pressing the Set Config button, the operator gives me the error the file cannot be found. The working directory has been changed to the data storage location (BCI2000\data\Name00) instead of the directory of the executable (BCI2000\prog).

Why does the program change the working directory?
[Edit]And why doesn't it change it back ;) [/edit]

To go with this

Posted: 05 Mar 2010, 11:25
by timo.veldt
If I make a parameter which has the inputfile designation in the comment, enabling the "browse to location"-button, I have to adjust (i.e. type an extra character, remove it again) the string (obtained through the "browse"-button) before the value is updated in the program.

Is there a way to fix this?

Posted: 05 Mar 2010, 11:50
by mellinger
When running the program and pressing the Set Config button, the operator gives me the error the file cannot be found. The working directory has been changed to the data storage location (BCI2000\data\Name00) instead of the directory of the executable (BCI2000\prog).
Relying on a certain behavior wrt to the working directory is not a good strategy.
BCI2000 provides functions for dealing with the application's installation directory. These are declared in BCI2000/src/shared/fileio/BCIDirectory.h.
string BCIDirectory::InstallationDirectory()
returns the absolute path to the module's installation directory, and
string BCIDirectory::AbsolutePath(string)
translates an application-relative path into an absolute one (leaving an absolute path unchanged).
If I make a parameter which has the inputfile designation in the comment, enabling the "browse to location"-button, I have to adjust (i.e. type an extra character, remove it again) the string (obtained through the "browse"-button) before the value is updated in the program.

Is there a way to fix this?
This is a bug that has been fixed in rev. 2696.

Posted: 03 Aug 2010, 14:02
by stefan
Relying on a certain behavior wrt to the working directory is not a good strategy.
I just ran into a similar problem where I had a script with relative path executed from the --OnStart command and after loading a parameter file from a different folder it could not be found anymore. There also seems to be an inconsistency between running operat.exe --OnConnect "-LOAD PARAMETERFILE ..." (does not change working dir) and manually loading a parm file (changes working dir). It would be nice if BCI2000 could keep a consistent "working directory" for a session. That would also make it easier with regard to moving files to a different folder/drive/system.

Stefan

Posted: 04 Aug 2010, 10:23
by mellinger
Due to your requests, BCI2000 now no longer changes working directories. This applies to both the Operator module and core modules.

Best regards,
Juergen

Posted: 06 Aug 2010, 16:09
by stefan
This is great news, thank you!