In brash.exe, Control-C is captured by the executable in the normal Window console application way.

When running brash using the -c or the -script options, not much is done -- the application just terminates.

When running from the console, however, Control-C sets a flag that remains true until all threads except the console reader thread have terminated. In addition to this global "shut down now flag", all outstanding i/o operations are cancelled using the CancelIoExc() function call. This allows for the termination of almost every i/o operation going on in the application.

However, for this to work properly, all code that reads from a file as part of brash.exe itself must check for the error code that means: I/O has been cancelled. Typically, this means throwing an exception in the read routine. The reader the exception is handled at the top level of each command executor thread. The handler just terminates the current thread and lets the thread go back to the command handler pool.

Basically, this means that all code running in brash.exe must be designed specifcally to enable I/O cancellation. This is done automatically if you use the read/write routines that are part of the execution context. See any built in function implementation in brashBuiltins.cxx.

If you write your own low level i/o operations, you need to be cognizant of this requirement. See brashCommands.cxx for the names of global variables set and checked for the control-C handler.

In the cxx/lib directory, a few functions check for a different flag -- this flag is obtained via a function call. See thisapplication.cxx. In brash, the function of interest is superseeded so that when you press control-C, the function return true until all threads terminate then it goes back to false.