return out.str();
string outstr = out.str(); for (int s = 0; s < outstr.size(); s++) if (outstr[s] == '\n') outstr[s] = ' ';  return outstr;
string doCommandStr(string command){  ostringstream out;  command = substVars(command);  logFile << timeStr() << "Running: " << command << endl;  int fd[2];    if (pipe(fd) < 0){    logFile << timeStr() << "Failed to create pipe" << endl;    finish(1);  }  int status;  pid_t process = fork();  if (process == -1){    logFile << timeStr() << "Could not fork!" << endl;    finish(1);  }  if (process == 0){ // child    close(fd[0]); // don't need to read    if (dup2(fd[1], fileno(stdout)) == -1){// redirect stdout       logFile << timeStr() << "Could not redirect stdout" << endl;       finish(1);    }    execlp("/bin/sh", "/bin/sh", "-c", command.c_str(), NULL);    logFile << timeStr() << "Could not exec command: " << command << endl;    finish(1);  } else {    close(fd[1]);    char buf[MAX_STRING];    int nread;    while ((nread = read(fd[0], buf, MAX_STRING)) > 0){      buf[nread] = 0;      //      printf("got %s\n", buf);      out.write(buf, nread);    }    if (nread == -1)      logFile << timeStr() << "Could not read from pipe" << endl;    //    logFile << "waiting " << endl;    close(fd[0]);    waitpid(process, & status, 0);  }  #ifdef WCOREDUMP  if (WCOREDUMP(status)){    logFile << timeStr() << "Command: " << command << " exited with a coredump"	    << endl;    cerr << "Command: " << command << " exited with a coredump" << endl;    finish(1);  }#endif  if (WIFEXITED(status) == 0){    logFile << timeStr() << "Command: " << command << " failed: likely through abort() or coredump" << endl;    cerr << "Command: " << command << " failed: likely through abort() or coredump" << endl;    finish(1);  }  // here we assume that WIFEXITED(status) is non null(should have been caught)  if (WEXITSTATUS(status) != 0){    logFile << timeStr() << "Command: " << command << " exited with status: " 	    << WEXITSTATUS(status) << endl;    cerr << "Command: " << command << " exited with status: " << WEXITSTATUS(status) << endl;    finish(1);  }  return out.str();} // doCommandStr