Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions bsubmit/bsubmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,23 @@ bool verifyUserMapping(std::string fpath, std::string execName)
}


void runcmd(std::string cmd)
int runcmd(std::string cmd)
{
std::string readline;
FILE * fp = popen(cmd.c_str(), "r");
if (fp != NULL) {
char buffer[4096];
while(fgets(buffer, sizeof(buffer) - 1, fp) != NULL) {
std::cout << buffer;
}
if (!fp) {
throw std::runtime_error("popen() failed!");
}

pclose(fp);
char buffer[4096];
while(fgets(buffer, sizeof(buffer) - 1, fp) != NULL) {
std::cout << buffer;
}
// pclose returns the termination status of the command
int status = pclose(fp);
// Extract the exit code from the status
// WEXITSTATUS is a macro that gets the actual return value (0-255)
int exit_code = WEXITSTATUS(status);
return exit_code;
}

int changeUser(char * execUser)
Expand Down Expand Up @@ -376,7 +381,7 @@ int main(int argc, char **argv)
bsubcmd.append(" ");
bsubcmd.append(argv[i]);
}
runcmd(bsubcmd);
int exit_code = runcmd(bsubcmd);

return 0;
return exit_code;
}