Skip to content

Commit

Permalink
Fix exit code capture
Browse files Browse the repository at this point in the history
  • Loading branch information
loganharbour authored and milljm committed Sep 27, 2024
1 parent 14adc98 commit bd55828
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion framework/include/base/MooseApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 19 additions & 16 deletions framework/src/base/MooseApp.C
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>("copy_inputs");

Expand Down Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -1712,13 +1716,12 @@ MooseApp::runInputs()
" --run <dir>\" 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;
}

Expand Down

0 comments on commit bd55828

Please sign in to comment.