Add -r/-e options to redirect stdout/stderr.
Better than using shell since it automatically uses -d directory for output files (creating it as needed).
This commit is contained in:
parent
50ef39af82
commit
fe8aeff362
2 changed files with 35 additions and 6 deletions
|
@ -60,12 +60,6 @@ OutputDirectory::setDirectory(const string &d)
|
|||
|
||||
dir = d;
|
||||
|
||||
if (dir != ".") {
|
||||
if (mkdir(dir.c_str(), 0777) < 0 && errno != EEXIST)
|
||||
panic("couldn't make output dir %s: %s\n",
|
||||
dir, strerror(errno));
|
||||
}
|
||||
|
||||
// guarantee that directory ends with a '/'
|
||||
if (dir[dir.size() - 1] != '/')
|
||||
dir += "/";
|
||||
|
|
|
@ -82,6 +82,14 @@ add_option('-N', "--release-notes", action="store_true", default=False,
|
|||
# Options for configuring the base simulator
|
||||
add_option('-d', "--outdir", metavar="DIR", default=".",
|
||||
help="Set the output directory to DIR [Default: %default]")
|
||||
add_option('-r', "--redirect-stdout", action="store_true", default=False,
|
||||
help="Redirect stdout (& stderr, without -e) to file")
|
||||
add_option('-e', "--redirect-stderr", action="store_true", default=False,
|
||||
help="Redirect stderr to file")
|
||||
add_option("--stdout-file", metavar="FILE", default="simout",
|
||||
help="Filename for -r redirection [Default: %default]")
|
||||
add_option("--stderr-file", metavar="FILE", default="simerr",
|
||||
help="Filename for -e redirection [Default: %default]")
|
||||
add_option('-i', "--interactive", action="store_true", default=False,
|
||||
help="Invoke the interactive interpreter after running the script")
|
||||
add_option("--pdb", action="store_true", default=False,
|
||||
|
@ -138,6 +146,33 @@ def main():
|
|||
|
||||
arguments = options.parse_args()
|
||||
|
||||
if not os.path.isdir(options.outdir):
|
||||
os.makedirs(options.outdir)
|
||||
|
||||
# These filenames are used only if the redirect_std* options are set
|
||||
stdout_file = os.path.join(options.outdir, options.stdout_file)
|
||||
stderr_file = os.path.join(options.outdir, options.stderr_file)
|
||||
|
||||
# Print redirection notices here before doing any redirection
|
||||
if options.redirect_stdout and not options.redirect_stderr:
|
||||
print "Redirecting stdout and stderr to", stdout_file
|
||||
else:
|
||||
if options.redirect_stdout:
|
||||
print "Redirecting stdout to", stdout_file
|
||||
if options.redirect_stderr:
|
||||
print "Redirecting stderr to", stderr_file
|
||||
|
||||
# Now redirect stdout/stderr as desired
|
||||
if options.redirect_stdout:
|
||||
redir_fd = os.open(stdout_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC)
|
||||
os.dup2(redir_fd, sys.stdout.fileno())
|
||||
if not options.redirect_stderr:
|
||||
os.dup2(redir_fd, sys.stderr.fileno())
|
||||
|
||||
if options.redirect_stderr:
|
||||
redir_fd = os.open(stderr_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC)
|
||||
os.dup2(redir_fd, sys.stderr.fileno())
|
||||
|
||||
done = False
|
||||
|
||||
if options.build_info:
|
||||
|
|
Loading…
Reference in a new issue