Commit 9f2c6144 authored by Steven Murray's avatar Steven Murray
Browse files

Added the --stderr option the cta command-line tool

parent 1f78ffa8
......@@ -36,6 +36,24 @@
#include <unistd.h>
#include <stdexcept>
/**
* Returns true if --stderr is on the command-line.
*
* @param argc The number of command-line arguments.
* @param argv The command-line arguments.
*/
static bool stderrIsOnTheCmdLine(const int argc, const char *const *const argv) {
for(int i = 1; i < argc; i++) {
const std::string arg = argv[i];
if(arg == "--stderr") {
return true;
}
}
return false;
}
/**
* Replaces all occurrences in a string "str" of a substring "from" with the string "to"
*
......@@ -102,6 +120,7 @@ std::string formatCommandPath(const int argc, const char **argv) {
*/
int sendCommand(const int argc, const char **argv) {
const bool writeToStderr = stderrIsOnTheCmdLine(argc, argv);
int p[2];
pipe(p); //Pipe to redirect std::out
int saved_stdout = dup(STDOUT_FILENO); //Saving std::out for later usage (re-redirection)
......@@ -151,6 +170,9 @@ int sendCommand(const int argc, const char **argv) {
while(read(p[0], buf, sizeof(buf)-1)>0) { //read the rest of the answer and pipe it to std::err
buf[sizeof(buf)-1]=0;
std::cout<<buf;
if(writeToStderr) {
std::cerr<<buf;
}
bzero(buf, sizeof(buf));
}
close(p[0]);
......
......@@ -2303,6 +2303,14 @@ std::string XrdCtaFile::getGenericHelp(const std::string &programName) const {
help << programName << " retrieve/r" << std::endl;
help << programName << " updatefileinfo/ufi" << std::endl;
help << programName << " updatefilestorageclass/ufsc" << std::endl;
help << "" << std::endl;
help << "Special option for running " << programName << " within the EOS worflow engine:" << std::endl;
help << "" << std::endl;
help << programName << " ... --stderr" << std::endl;
help << "" << std::endl;
help << "The option tells " << programName << " to write results to both standard out and standard error." <<
std::endl;
help << "The option must be specified as the very last command-line argument of " << programName << "." << std::endl;
return help.str();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment