Public Member Functions | |
BLCMDoutput () | |
G4String | commandName () |
int | command (BLArgumentVector &argv, BLArgumentMap &namedArgs) |
BLCMDoutput::BLCMDoutput | ( | ) |
References BLCMDTYPE_CONTROL, BLCommand::registerCommand(), BLCommand::setDescription(), and BLCommand::setSynopsis().
00041 { 00042 registerCommand(BLCMDTYPE_CONTROL); 00043 setSynopsis("redirects stdout and stderr to a file"); 00044 setDescription("output requires one argument, the new output file. " 00045 "Any output generated before this command will not appear in " 00046 "the file, so this command should come at the start of the " 00047 "input.file, preceded only by setting parameters. After the " 00048 "redirection, it will re-print the G4beamline version and the " 00049 "current parameter values to the file. The most common usage " 00050 "is to redirect output to a file named like the .root file, " 00051 "when that is determined by parameter values:\n" 00052 " param -unset param1=1.0 param2=3.0\n" 00053 " param histofile=$param1,$param2\n" 00054 " output $histofile.out"); 00055 }
G4String BLCMDoutput::commandName | ( | ) | [inline, virtual] |
int BLCMDoutput::command | ( | BLArgumentVector & | argv, | |
BLArgumentMap & | namedArgs | |||
) | [virtual] |
Implements BLCommand.
References Param, BLCommand::printError(), BLParam::printParam(), and startupPrint().
00058 { 00059 if(argv.size() != 1 || namedArgs.size() != 0) { 00060 printError("Invalid output command"); 00061 return -1; 00062 } 00063 00064 FILE *f = fopen(argv[0].c_str(),"w"); 00065 if(!f) { 00066 printError("output: cannot open '%s'\n",argv[0].c_str()); 00067 } 00068 fclose(f); 00069 00070 printf("output redirected to '%s'\n",argv[0].c_str()); 00071 00072 freopen(argv[0].c_str(),"w",stdout); 00073 freopen(argv[0].c_str(),"w",stderr); 00074 00075 startupPrint(false); 00076 printf("... output redirected to this file '%s'.\n",argv[0].c_str()); 00077 Param.printParam(); 00078 printf("\n"); 00079 00080 return 0; 00081 }