From 14adc9857c23a40c6193d771434196988754bf29 Mon Sep 17 00:00:00 2001 From: Logan Harbour Date: Tue, 27 Aug 2024 10:00:31 -0600 Subject: [PATCH 1/4] Capture return code and use it for --run refs #28639 --- examples/ex01_inputfile/src/main.C | 4 +--- examples/ex02_kernel/src/main.C | 4 +--- examples/ex03_coupling/src/main.C | 4 +--- examples/ex04_bcs/src/main.C | 4 +--- examples/ex05_amr/src/main.C | 4 +--- examples/ex06_transient/src/main.C | 4 +--- examples/ex07_ics/src/main.C | 4 +--- examples/ex08_materials/src/main.C | 4 +--- examples/ex09_stateful_materials/src/main.C | 4 +--- examples/ex10_aux/src/main.C | 4 +--- examples/ex11_prec/src/main.C | 4 +--- examples/ex12_pbp/src/main.C | 4 +--- examples/ex13_functions/src/main.C | 4 +--- examples/ex14_pps/src/main.C | 4 +--- examples/ex15_actions/src/main.C | 4 +--- examples/ex16_timestepper/src/main.C | 4 +--- examples/ex17_dirac/src/main.C | 4 +--- examples/ex18_scalar_kernel/src/main.C | 4 +--- examples/ex19_dampers/src/main.C | 4 +--- examples/ex20_user_objects/src/main.C | 4 +--- examples/ex21_debugging/src/main.C | 4 +--- framework/include/base/MooseApp.h | 10 +++++++++- framework/include/base/MooseMain.h | 4 +++- framework/src/base/MooseApp.C | 8 +++----- modules/chemical_reactions/src/main.C | 4 +--- modules/combined/src/main.C | 4 +--- modules/contact/src/main.C | 4 +--- modules/electromagnetics/src/main.C | 4 +--- modules/external_petsc_solver/src/main.C | 4 +--- modules/fluid_properties/src/main.C | 4 +--- modules/fsi/src/main.C | 4 +--- modules/functional_expansion_tools/src/main.C | 4 +--- modules/geochemistry/src/main.C | 4 +--- modules/heat_transfer/src/main.C | 4 +--- modules/level_set/src/main.C | 4 +--- modules/misc/src/main.C | 4 +--- modules/navier_stokes/src/main.C | 4 +--- modules/optimization/src/main.C | 4 +--- modules/peridynamics/src/main.C | 4 +--- modules/phase_field/src/main.C | 4 +--- modules/porous_flow/src/main.C | 4 +--- modules/ray_tracing/src/main.C | 4 +--- modules/rdg/src/main.C | 4 +--- modules/reactor/src/main.C | 4 +--- modules/richards/src/main.C | 4 +--- modules/scalar_transport/src/main.C | 4 +--- modules/solid_mechanics/src/main.C | 4 +--- modules/solid_properties/src/main.C | 4 +--- modules/stochastic_tools/src/main.C | 4 +--- modules/thermal_hydraulics/src/main.C | 4 +--- modules/xfem/src/main.C | 4 +--- stork/src/main.C | 4 +--- test/src/main.C | 4 +--- .../darcy_thermo_mech/step01_diffusion/src/main.C | 4 +--- .../step01_moose_app/src/main.C | 4 +--- .../step02_input_file/src/main.C | 4 +--- .../step05_kernel_object/src/main.C | 4 +--- .../step06_input_params/src/main.C | 4 +--- .../step08_test_harness/src/main.C | 4 +--- .../step09_mat_props/src/main.C | 4 +--- .../step10_auxkernels/src/main.C | 4 +--- tutorials/tutorial02_multiapps/app/src/main.C | 4 +--- tutorials/tutorial03_verification/app/src/main.C | 4 +--- tutorials/tutorial04_meshing/app/src/main.C | 4 +--- 64 files changed, 76 insertions(+), 190 deletions(-) diff --git a/examples/ex01_inputfile/src/main.C b/examples/ex01_inputfile/src/main.C index a19ed87ff08d..382121480dcd 100644 --- a/examples/ex01_inputfile/src/main.C +++ b/examples/ex01_inputfile/src/main.C @@ -20,7 +20,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex02_kernel/src/main.C b/examples/ex02_kernel/src/main.C index c9d548fb605e..0df7c7b0868b 100644 --- a/examples/ex02_kernel/src/main.C +++ b/examples/ex02_kernel/src/main.C @@ -20,7 +20,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex03_coupling/src/main.C b/examples/ex03_coupling/src/main.C index 42e36c548a31..f537d53edc42 100644 --- a/examples/ex03_coupling/src/main.C +++ b/examples/ex03_coupling/src/main.C @@ -22,7 +22,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex04_bcs/src/main.C b/examples/ex04_bcs/src/main.C index 3a2063e1962c..0e835a3df1e9 100644 --- a/examples/ex04_bcs/src/main.C +++ b/examples/ex04_bcs/src/main.C @@ -21,7 +21,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex05_amr/src/main.C b/examples/ex05_amr/src/main.C index aa9cc4318301..8d2fc43b671a 100644 --- a/examples/ex05_amr/src/main.C +++ b/examples/ex05_amr/src/main.C @@ -21,7 +21,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex06_transient/src/main.C b/examples/ex06_transient/src/main.C index 932975809e37..8e16ac770f92 100644 --- a/examples/ex06_transient/src/main.C +++ b/examples/ex06_transient/src/main.C @@ -22,7 +22,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex07_ics/src/main.C b/examples/ex07_ics/src/main.C index 4822cd60d390..2cf42e1410c3 100644 --- a/examples/ex07_ics/src/main.C +++ b/examples/ex07_ics/src/main.C @@ -20,7 +20,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex08_materials/src/main.C b/examples/ex08_materials/src/main.C index 8416a759b17c..29dbebfed886 100644 --- a/examples/ex08_materials/src/main.C +++ b/examples/ex08_materials/src/main.C @@ -20,7 +20,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex09_stateful_materials/src/main.C b/examples/ex09_stateful_materials/src/main.C index 65b5a553f374..183476393095 100644 --- a/examples/ex09_stateful_materials/src/main.C +++ b/examples/ex09_stateful_materials/src/main.C @@ -22,7 +22,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex10_aux/src/main.C b/examples/ex10_aux/src/main.C index ad4e9e80262b..ac6d9fa058ae 100644 --- a/examples/ex10_aux/src/main.C +++ b/examples/ex10_aux/src/main.C @@ -20,7 +20,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex11_prec/src/main.C b/examples/ex11_prec/src/main.C index 6793c1bf621f..519e802ee113 100644 --- a/examples/ex11_prec/src/main.C +++ b/examples/ex11_prec/src/main.C @@ -20,7 +20,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex12_pbp/src/main.C b/examples/ex12_pbp/src/main.C index 6793c1bf621f..519e802ee113 100644 --- a/examples/ex12_pbp/src/main.C +++ b/examples/ex12_pbp/src/main.C @@ -20,7 +20,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex13_functions/src/main.C b/examples/ex13_functions/src/main.C index 7cd17b2741af..fd5b26fe3047 100644 --- a/examples/ex13_functions/src/main.C +++ b/examples/ex13_functions/src/main.C @@ -18,7 +18,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex14_pps/src/main.C b/examples/ex14_pps/src/main.C index 074f53232cc3..ec1e74f7f0a5 100644 --- a/examples/ex14_pps/src/main.C +++ b/examples/ex14_pps/src/main.C @@ -25,7 +25,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex15_actions/src/main.C b/examples/ex15_actions/src/main.C index bbb0ee832ef7..8f2d20d20e4d 100644 --- a/examples/ex15_actions/src/main.C +++ b/examples/ex15_actions/src/main.C @@ -22,7 +22,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex16_timestepper/src/main.C b/examples/ex16_timestepper/src/main.C index 8c77953ee16a..504bb73c6dde 100644 --- a/examples/ex16_timestepper/src/main.C +++ b/examples/ex16_timestepper/src/main.C @@ -22,7 +22,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex17_dirac/src/main.C b/examples/ex17_dirac/src/main.C index 7c8f989526e4..f5b245f77d2f 100644 --- a/examples/ex17_dirac/src/main.C +++ b/examples/ex17_dirac/src/main.C @@ -18,7 +18,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex18_scalar_kernel/src/main.C b/examples/ex18_scalar_kernel/src/main.C index f48f8edf9082..416e2b89b618 100644 --- a/examples/ex18_scalar_kernel/src/main.C +++ b/examples/ex18_scalar_kernel/src/main.C @@ -18,7 +18,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex19_dampers/src/main.C b/examples/ex19_dampers/src/main.C index dc6ca2f2a8bc..2e064a785589 100644 --- a/examples/ex19_dampers/src/main.C +++ b/examples/ex19_dampers/src/main.C @@ -18,7 +18,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex20_user_objects/src/main.C b/examples/ex20_user_objects/src/main.C index 47bdf8de396b..f132e9b02c68 100644 --- a/examples/ex20_user_objects/src/main.C +++ b/examples/ex20_user_objects/src/main.C @@ -18,7 +18,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/examples/ex21_debugging/src/main.C b/examples/ex21_debugging/src/main.C index 8416a759b17c..29dbebfed886 100644 --- a/examples/ex21_debugging/src/main.C +++ b/examples/ex21_debugging/src/main.C @@ -20,7 +20,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/framework/include/base/MooseApp.h b/framework/include/base/MooseApp.h index 3897050619a4..ccf144729941 100644 --- a/framework/include/base/MooseApp.h +++ b/framework/include/base/MooseApp.h @@ -128,6 +128,12 @@ class MooseApp : public ConsoleStreamInterface, return name; } + /** + * Get the shell exit code for the application + * @return The shell exit code + */ + int exitCode() const { return _exit_code; } + /** * Get the parameters of the object * @return The parameters of the object @@ -1234,6 +1240,8 @@ class MooseApp : public ConsoleStreamInterface, /// Indicates whether warnings or errors are displayed when overridden parameters are detected bool _error_overridden; bool _ready_to_exit; + /// The exit code + int _exit_code; /// This variable indicates when a request has been made to restart from an Exodus file bool _initial_from_file; @@ -1412,7 +1420,7 @@ class MooseApp : public ConsoleStreamInterface, * and launches the TestHarness to process the given directory. * @return a Boolean value used to indicate whether the application should exit early */ - bool runInputs() const; + bool runInputs(); /// General storage for custom RestartableData that can be added to from outside applications std::unordered_map> diff --git a/framework/include/base/MooseMain.h b/framework/include/base/MooseMain.h index 61017dc2568f..fbb479bfb1aa 100644 --- a/framework/include/base/MooseMain.h +++ b/framework/include/base/MooseMain.h @@ -33,7 +33,7 @@ void addMainCommandLineParams(InputParameters & params); * Initialize, create and run a MooseApp */ template -void +int main(int argc, char * argv[]) { MooseInit init(argc, argv); @@ -45,5 +45,7 @@ main(int argc, char * argv[]) auto app = createMooseApp(default_app_name, argc, argv); app->run(); + + return app->exitCode(); } } diff --git a/framework/src/base/MooseApp.C b/framework/src/base/MooseApp.C index 3b98be65101a..dbcb003538ba 100644 --- a/framework/src/base/MooseApp.C +++ b/framework/src/base/MooseApp.C @@ -403,6 +403,7 @@ MooseApp::MooseApp(InputParameters parameters) _factory(*this), _error_overridden(false), _ready_to_exit(false), + _exit_code(0), _initial_from_file(false), _distributed_mesh_on_command_line(false), _recover(false), @@ -1669,7 +1670,7 @@ MooseApp::copyInputs() const } bool -MooseApp::runInputs() const +MooseApp::runInputs() { if (isParamValid("run")) { @@ -1717,10 +1718,7 @@ MooseApp::runInputs() const if (processor_id() == 0) return_value = system(cmd.c_str()); _communicator.broadcast(return_value); - - // TODO: return the actual return value here - if (WIFEXITED(return_value) && WEXITSTATUS(return_value) != 0) - mooseError("Run failed"); + _exit_code = return_value; return true; } diff --git a/modules/chemical_reactions/src/main.C b/modules/chemical_reactions/src/main.C index 79b51b86f8c7..0ad8d59ba89e 100644 --- a/modules/chemical_reactions/src/main.C +++ b/modules/chemical_reactions/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/combined/src/main.C b/modules/combined/src/main.C index ae452bfc3fa1..af9492f00cdf 100644 --- a/modules/combined/src/main.C +++ b/modules/combined/src/main.C @@ -18,7 +18,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/contact/src/main.C b/modules/contact/src/main.C index fbf07f726aae..a6940aca0bc1 100644 --- a/modules/contact/src/main.C +++ b/modules/contact/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/electromagnetics/src/main.C b/modules/electromagnetics/src/main.C index bce75c1e64da..08f660cfa8c7 100644 --- a/modules/electromagnetics/src/main.C +++ b/modules/electromagnetics/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/external_petsc_solver/src/main.C b/modules/external_petsc_solver/src/main.C index 036e6eb97cac..a98ec6729630 100644 --- a/modules/external_petsc_solver/src/main.C +++ b/modules/external_petsc_solver/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/fluid_properties/src/main.C b/modules/fluid_properties/src/main.C index cc4f837ac0a3..4bceed8cc3e7 100644 --- a/modules/fluid_properties/src/main.C +++ b/modules/fluid_properties/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/fsi/src/main.C b/modules/fsi/src/main.C index cebe72b1857f..53e1fc9efe41 100644 --- a/modules/fsi/src/main.C +++ b/modules/fsi/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/functional_expansion_tools/src/main.C b/modules/functional_expansion_tools/src/main.C index f48d6066cdaa..4dfca5e188f0 100644 --- a/modules/functional_expansion_tools/src/main.C +++ b/modules/functional_expansion_tools/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/geochemistry/src/main.C b/modules/geochemistry/src/main.C index 01dc03aac9e1..3b3c8e3a22fc 100644 --- a/modules/geochemistry/src/main.C +++ b/modules/geochemistry/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/heat_transfer/src/main.C b/modules/heat_transfer/src/main.C index d4559bb548ab..38d377208d35 100644 --- a/modules/heat_transfer/src/main.C +++ b/modules/heat_transfer/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/level_set/src/main.C b/modules/level_set/src/main.C index 2b76c8b657a6..36c6da0a6610 100644 --- a/modules/level_set/src/main.C +++ b/modules/level_set/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/misc/src/main.C b/modules/misc/src/main.C index 655f54623582..b4e2cfc8025a 100644 --- a/modules/misc/src/main.C +++ b/modules/misc/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/navier_stokes/src/main.C b/modules/navier_stokes/src/main.C index 72ec2c82b41b..1a1c4b947d2c 100644 --- a/modules/navier_stokes/src/main.C +++ b/modules/navier_stokes/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/optimization/src/main.C b/modules/optimization/src/main.C index b50c18d11a9c..9a3f5241988a 100644 --- a/modules/optimization/src/main.C +++ b/modules/optimization/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/peridynamics/src/main.C b/modules/peridynamics/src/main.C index e4e9f51c58d0..24e88d1b1f3c 100644 --- a/modules/peridynamics/src/main.C +++ b/modules/peridynamics/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/phase_field/src/main.C b/modules/phase_field/src/main.C index 8f6d04cc976d..39a66582284e 100644 --- a/modules/phase_field/src/main.C +++ b/modules/phase_field/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/porous_flow/src/main.C b/modules/porous_flow/src/main.C index f2bd3b0c299b..532612152d42 100644 --- a/modules/porous_flow/src/main.C +++ b/modules/porous_flow/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/ray_tracing/src/main.C b/modules/ray_tracing/src/main.C index 23868752962c..d6d2a14d25ed 100644 --- a/modules/ray_tracing/src/main.C +++ b/modules/ray_tracing/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/rdg/src/main.C b/modules/rdg/src/main.C index f91df30b5272..120c84cba9ac 100644 --- a/modules/rdg/src/main.C +++ b/modules/rdg/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/reactor/src/main.C b/modules/reactor/src/main.C index 6b514df61cac..995d8a26840a 100644 --- a/modules/reactor/src/main.C +++ b/modules/reactor/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/richards/src/main.C b/modules/richards/src/main.C index 9eb63559a231..2bbb798c3e51 100644 --- a/modules/richards/src/main.C +++ b/modules/richards/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/scalar_transport/src/main.C b/modules/scalar_transport/src/main.C index 5a12efa14a60..e1036e14b5cd 100644 --- a/modules/scalar_transport/src/main.C +++ b/modules/scalar_transport/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/solid_mechanics/src/main.C b/modules/solid_mechanics/src/main.C index 7b757b228591..d6f136701013 100644 --- a/modules/solid_mechanics/src/main.C +++ b/modules/solid_mechanics/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/solid_properties/src/main.C b/modules/solid_properties/src/main.C index b0e73f8054db..a64f2e7a0137 100644 --- a/modules/solid_properties/src/main.C +++ b/modules/solid_properties/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/stochastic_tools/src/main.C b/modules/stochastic_tools/src/main.C index 73a8a20f567a..c721c755fc77 100644 --- a/modules/stochastic_tools/src/main.C +++ b/modules/stochastic_tools/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/thermal_hydraulics/src/main.C b/modules/thermal_hydraulics/src/main.C index 22ecff94be1d..5025fc6aba5f 100644 --- a/modules/thermal_hydraulics/src/main.C +++ b/modules/thermal_hydraulics/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/modules/xfem/src/main.C b/modules/xfem/src/main.C index 760c41539850..98445604f3c7 100644 --- a/modules/xfem/src/main.C +++ b/modules/xfem/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/stork/src/main.C b/stork/src/main.C index fc554f48a0ab..8a83fa6f8a5c 100644 --- a/stork/src/main.C +++ b/stork/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/test/src/main.C b/test/src/main.C index 68a3f1a07f2b..2200fcf1497d 100644 --- a/test/src/main.C +++ b/test/src/main.C @@ -13,7 +13,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/tutorials/darcy_thermo_mech/step01_diffusion/src/main.C b/tutorials/darcy_thermo_mech/step01_diffusion/src/main.C index 4074c7c7258a..4c94fcb7c9d6 100644 --- a/tutorials/darcy_thermo_mech/step01_diffusion/src/main.C +++ b/tutorials/darcy_thermo_mech/step01_diffusion/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/tutorials/tutorial01_app_development/step01_moose_app/src/main.C b/tutorials/tutorial01_app_development/step01_moose_app/src/main.C index 740d3f137e75..8ac7ccad5a08 100644 --- a/tutorials/tutorial01_app_development/step01_moose_app/src/main.C +++ b/tutorials/tutorial01_app_development/step01_moose_app/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/tutorials/tutorial01_app_development/step02_input_file/src/main.C b/tutorials/tutorial01_app_development/step02_input_file/src/main.C index 740d3f137e75..8ac7ccad5a08 100644 --- a/tutorials/tutorial01_app_development/step02_input_file/src/main.C +++ b/tutorials/tutorial01_app_development/step02_input_file/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/tutorials/tutorial01_app_development/step05_kernel_object/src/main.C b/tutorials/tutorial01_app_development/step05_kernel_object/src/main.C index 740d3f137e75..8ac7ccad5a08 100644 --- a/tutorials/tutorial01_app_development/step05_kernel_object/src/main.C +++ b/tutorials/tutorial01_app_development/step05_kernel_object/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/tutorials/tutorial01_app_development/step06_input_params/src/main.C b/tutorials/tutorial01_app_development/step06_input_params/src/main.C index 740d3f137e75..8ac7ccad5a08 100644 --- a/tutorials/tutorial01_app_development/step06_input_params/src/main.C +++ b/tutorials/tutorial01_app_development/step06_input_params/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/tutorials/tutorial01_app_development/step08_test_harness/src/main.C b/tutorials/tutorial01_app_development/step08_test_harness/src/main.C index 740d3f137e75..8ac7ccad5a08 100644 --- a/tutorials/tutorial01_app_development/step08_test_harness/src/main.C +++ b/tutorials/tutorial01_app_development/step08_test_harness/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/tutorials/tutorial01_app_development/step09_mat_props/src/main.C b/tutorials/tutorial01_app_development/step09_mat_props/src/main.C index 740d3f137e75..8ac7ccad5a08 100644 --- a/tutorials/tutorial01_app_development/step09_mat_props/src/main.C +++ b/tutorials/tutorial01_app_development/step09_mat_props/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/tutorials/tutorial01_app_development/step10_auxkernels/src/main.C b/tutorials/tutorial01_app_development/step10_auxkernels/src/main.C index 740d3f137e75..8ac7ccad5a08 100644 --- a/tutorials/tutorial01_app_development/step10_auxkernels/src/main.C +++ b/tutorials/tutorial01_app_development/step10_auxkernels/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/tutorials/tutorial02_multiapps/app/src/main.C b/tutorials/tutorial02_multiapps/app/src/main.C index c5b034771f78..9b17f3eabf39 100644 --- a/tutorials/tutorial02_multiapps/app/src/main.C +++ b/tutorials/tutorial02_multiapps/app/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/tutorials/tutorial03_verification/app/src/main.C b/tutorials/tutorial03_verification/app/src/main.C index 4f50b354c023..f32e426baaac 100644 --- a/tutorials/tutorial03_verification/app/src/main.C +++ b/tutorials/tutorial03_verification/app/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } diff --git a/tutorials/tutorial04_meshing/app/src/main.C b/tutorials/tutorial04_meshing/app/src/main.C index e8decd83fe76..34d543fe49a9 100644 --- a/tutorials/tutorial04_meshing/app/src/main.C +++ b/tutorials/tutorial04_meshing/app/src/main.C @@ -14,7 +14,5 @@ int main(int argc, char * argv[]) { - Moose::main(argc, argv); - - return 0; + return Moose::main(argc, argv); } From bd55828f5eb777e3d9d4ac668b6ca72c54336c48 Mon Sep 17 00:00:00 2001 From: Logan Harbour Date: Wed, 28 Aug 2024 17:51:03 -0600 Subject: [PATCH 2/4] Fix exit code capture refs #28639 --- framework/include/base/MooseApp.h | 2 +- framework/src/base/MooseApp.C | 35 +++++++++++++++++-------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/framework/include/base/MooseApp.h b/framework/include/base/MooseApp.h index ccf144729941..7cd4ccfc52d3 100644 --- a/framework/include/base/MooseApp.h +++ b/framework/include/base/MooseApp.h @@ -1413,7 +1413,7 @@ class MooseApp : public ConsoleStreamInterface, * read/writable location for the user. * @return a Boolean value used to indicate whether the application should exit early */ - bool copyInputs() const; + bool copyInputs(); /** * Handles the run input parameter logic: Checks to see whether a directory exists in user space diff --git a/framework/src/base/MooseApp.C b/framework/src/base/MooseApp.C index dbcb003538ba..7e9fe63f152b 100644 --- a/framework/src/base/MooseApp.C +++ b/framework/src/base/MooseApp.C @@ -1606,10 +1606,13 @@ MooseApp::getInstallableInputs() const } bool -MooseApp::copyInputs() const +MooseApp::copyInputs() { if (isParamValid("copy_inputs")) { + if (comm().size() > 1) + mooseError("The --copy-inputs option should not be ran in parallel"); + // Get command line argument following --copy-inputs on command line auto dir_to_copy = getParam("copy_inputs"); @@ -1655,15 +1658,13 @@ MooseApp::copyInputs() const TIME_SECTION("copy_inputs", 2, "Copying Inputs"); - // Only perform the copy on the root processor - int return_value = 0; - if (processor_id() == 0) - return_value = system(cmd.c_str()); - _communicator.broadcast(return_value); - - if (WIFEXITED(return_value) && WEXITSTATUS(return_value) != 0) - mooseError("Failed to copy the requested directory."); - Moose::out << "Directory successfully copied into ./" << dst_dir << '\n'; + mooseAssert(comm().size() == 1, "Should be run in serial"); + const auto return_value = system(cmd.c_str()); + if (!WIFEXITED(return_value)) + mooseError("Process exited unexpectedly"); + _exit_code = WEXITSTATUS(return_value); + if (_exit_code == 0) + Moose::out << "Directory successfully copied into ./" << dst_dir << '\n'; return true; } return false; @@ -1677,6 +1678,9 @@ MooseApp::runInputs() // These options will show as unused by petsc; ignore them all Moose::PetscSupport::setSinglePetscOption("-options_left", "0"); + if (comm().size() > 1) + mooseError("The --run option should not be ran in parallel"); + // Here we are going to pass everything after --run on the cli to the TestHarness. That means // cannot validate these CLIs. auto it = _command_line->find("run"); @@ -1712,13 +1716,12 @@ MooseApp::runInputs() " --run \" again."); } - // Only launch the tests on the root processor Moose::out << "Working Directory: " << working_dir << "\nRunning Command: " << cmd << std::endl; - int return_value = 0; - if (processor_id() == 0) - return_value = system(cmd.c_str()); - _communicator.broadcast(return_value); - _exit_code = return_value; + mooseAssert(comm().size() == 1, "Should be run in serial"); + const auto return_value = system(cmd.c_str()); + if (!WIFEXITED(return_value)) + mooseError("Process exited unexpectedly"); + _exit_code = WEXITSTATUS(return_value); return true; } From e1f47c59a90e4e71bc56f3eca3ce3945bc36a2f1 Mon Sep 17 00:00:00 2001 From: Logan Harbour Date: Mon, 16 Sep 2024 17:18:10 -0600 Subject: [PATCH 3/4] Add exit code setter refs #28639 --- framework/include/base/MooseApp.h | 5 +++++ framework/src/base/MooseApp.C | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/framework/include/base/MooseApp.h b/framework/include/base/MooseApp.h index 7cd4ccfc52d3..7f2782320159 100644 --- a/framework/include/base/MooseApp.h +++ b/framework/include/base/MooseApp.h @@ -134,6 +134,11 @@ class MooseApp : public ConsoleStreamInterface, */ int exitCode() const { return _exit_code; } + /** + * Sets the exit code that the application will exit with. + */ + void setExitCode(const int exit_code) { _exit_code = exit_code; } + /** * Get the parameters of the object * @return The parameters of the object diff --git a/framework/src/base/MooseApp.C b/framework/src/base/MooseApp.C index 7e9fe63f152b..5d95db8d1c2d 100644 --- a/framework/src/base/MooseApp.C +++ b/framework/src/base/MooseApp.C @@ -1662,8 +1662,8 @@ MooseApp::copyInputs() const auto return_value = system(cmd.c_str()); if (!WIFEXITED(return_value)) mooseError("Process exited unexpectedly"); - _exit_code = WEXITSTATUS(return_value); - if (_exit_code == 0) + setExitCode(WEXITSTATUS(return_value)); + if (exitCode() == 0) Moose::out << "Directory successfully copied into ./" << dst_dir << '\n'; return true; } @@ -1721,7 +1721,7 @@ MooseApp::runInputs() const auto return_value = system(cmd.c_str()); if (!WIFEXITED(return_value)) mooseError("Process exited unexpectedly"); - _exit_code = WEXITSTATUS(return_value); + setExitCode(WEXITSTATUS(return_value)); return true; } From 342dfe75d4e7b4c928dd4d46bd7357d0ffc4e8ed Mon Sep 17 00:00:00 2001 From: Logan Harbour Date: Mon, 16 Sep 2024 17:23:03 -0600 Subject: [PATCH 4/4] Add newsletter entry on main exit code refs #28639 --- .../doc/content/newsletter/2024/2024_09.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/modules/doc/content/newsletter/2024/2024_09.md b/modules/doc/content/newsletter/2024/2024_09.md index 64efc847b999..82e2788bbccb 100644 --- a/modules/doc/content/newsletter/2024/2024_09.md +++ b/modules/doc/content/newsletter/2024/2024_09.md @@ -14,6 +14,32 @@ now provide interfaces to compute the specific internal energy as a function of temperature. This new interface is useful, for example, in measuring the internal energy in solids for energy conservation verification. +### Exit Code Management + +The ability was added to allow an application to set its exit code, which can +be seen in `MooseApp::setExitCode()`. This feature was added in order to better +support instances in which you want to run an external process within an application, +as the proper return code from the external process can be captured and +returned via your application. + +In order for an application properly return this exit code, a modification is needed +within the `main` function. To do this, modify the `main()` function in `src/main.C` +to look like the following: + +``` +int +main(int argc, char * argv[]) +{ + return Moose::main(argc, argv); +} +``` + +where `YourApp` is the class for your application. + +This change should be made as soon as possible as the logic that was changed here +impacts the application command line options `--run` and `--copy-inputs` used for +executing installed MOOSE applications. + ## libMesh-level Changes ## PETSc-level Changes