I am using a macro file when I run the compiled geant4 simulation program.
I can use all other commands in the macro file, but not “exit” (white picture)
the Geant4 simulation cannot read “exit” from the macro files, and the simulation is not terminated and is still in the edle (black picture)
I really want to use “exit” in the macro files, so I can make a shell script that runs the Geant4 simulation and close it, and run another Geant4 simulation and close it and do this.
How is your main() function structured? The canonical way to implement a program that permits interactive or batch processing can be seen in the basic “B1” example, something like:
nt main(int argc,char** argv)
{
// Detect interactive mode (if no arguments) and define UI session
//
G4UIExecutive* ui = nullptr;
if ( argc == 1 ) { ui = new G4UIExecutive(argc, argv); }
...
// Get the pointer to the User Interface manager
G4UImanager* UImanager = G4UImanager::GetUIpointer();
// Process macro or start UI session
//
if ( ! ui ) {
// batch mode
G4String command = "/control/execute ";
G4String fileName = argv[1];
UImanager->ApplyCommand(command+fileName);
}
else {
// interactive mode
UImanager->ApplyCommand("/control/execute init_vis.mac");
ui->SessionStart();
delete ui;
}
...
return 0;
}
This then runs in interactive mode (i.e. with a GUI or terminal UI) when run as
$ ./exampleB1
or in batch mode when run with an argument (path to macro):