Skip to content

run() with stdout ostream #2923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2018
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
36 changes: 29 additions & 7 deletions src/util/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,25 @@ Date: August 2012
#else

#include <cstring>
#include <unistd.h>
#include <cerrno>
#include <cstdio>
#include <cstdlib>

#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#endif

#include <util/invariant.h>
#include <util/unicode.h>
#include <util/signal_catcher.h>
#include <fstream>

#include "invariant.h"
#include "signal_catcher.h"
#include "tempfile.h"
#include "unicode.h"

int run(const std::string &what, const std::vector<std::string> &argv)
{
Expand Down Expand Up @@ -228,3 +231,22 @@ int run(
}
#endif
}

int run(
const std::string &what,
const std::vector<std::string> &argv,
const std::string &std_input,
std::ostream &std_output,
const std::string &std_error)
{
temporary_filet tmpi("tmp.stdout", "");

int result = run(what, argv, std_input, tmpi(), std_error);

std::ifstream instream(tmpi());

if(instream)
std_output << instream.rdbuf(); // copy

return result;
}
9 changes: 9 additions & 0 deletions src/util/run.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Date: August 2012
#ifndef CPROVER_UTIL_RUN_H
#define CPROVER_UTIL_RUN_H

#include <iosfwd>
#include <string>
#include <vector>

Expand All @@ -24,4 +25,12 @@ int run(
const std::string &std_output,
const std::string &std_error);

/// A variant that streams the stdout of the child into an ostream
int run(
const std::string &what,
const std::vector<std::string> &argv,
const std::string &std_input,
std::ostream &std_output,
const std::string &std_error);

#endif // CPROVER_UTIL_RUN_H