Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion core/base/inc/TSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ class TSystem : public TNamed {
virtual Int_t Exec(const char *shellcmd);
virtual FILE *OpenPipe(const char *command, const char *mode);
virtual int ClosePipe(FILE *pipe);
virtual TString GetFromPipe(const char *command);
virtual TString GetFromPipe(const char *command, Int_t *ret = nullptr, Bool_t redirectStderr = kFALSE);
virtual int GetPid();
virtual void StackTrace();

Expand Down
21 changes: 16 additions & 5 deletions core/base/src/TSystem.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,22 @@ int TSystem::ClosePipe(FILE*)

////////////////////////////////////////////////////////////////////////////////
/// Execute command and return output in TString.
/// @param command the command to be executed
/// @param ret pointer to the memory where to store the returned value of the
/// command, i.e. the result of ClosePipe (p-close stream, the status of its child).
/// If ret is nullptr, the returned value is not stored anywhere.
/// @param redirectStderr if true, stderr will be redirected to stdout
/// @return the stdout of the command as TString (from the p-opened FILE stream)

TString TSystem::GetFromPipe(const char *command)
TString TSystem::GetFromPipe(const char *command, Int_t *ret, Bool_t redirectStderr)
{
TString out;

FILE *pipe = OpenPipe(command, "r");
TString scommand = command;
if (redirectStderr)
scommand += " 2>&1";
FILE *pipe = OpenPipe(scommand.Data(), "r");
if (!pipe) {
SysError("GetFromPipe", "cannot run command \"%s\"", command);
SysError("GetFromPipe", "cannot run command \"%s\"", scommand.Data());
return out;
}

Expand All @@ -696,7 +704,10 @@ TString TSystem::GetFromPipe(const char *command)

Int_t r = ClosePipe(pipe);
if (r) {
Error("GetFromPipe", "command \"%s\" returned %d", command, r);
Error("GetFromPipe", "command \"%s\" returned %d", scommand.Data(), r);
}
if (ret) {
*ret = r;
}
return out;
}
Expand Down
Loading