From 63b622a086b1b6a02542802b6205a8295bdbcf06 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Thu, 24 Nov 2011 17:42:40 +0100 Subject: [PATCH] The shell now supports sending stdout to a file. --- utils/mxsh.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/utils/mxsh.cpp b/utils/mxsh.cpp index 8451c24e..ec4915fb 100644 --- a/utils/mxsh.cpp +++ b/utils/mxsh.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -108,6 +109,20 @@ void command() return; } + if ( 3 <= argc ) + { + if ( strcmp(argv[argc-2], ">") == 0 ) + { + const char* file = argv[argc-1]; + int outfd = open(file, O_CREAT | O_WRONLY | O_TRUNC | O_APPEND); + if ( outfd < 0 ) { printf("%s: %s\n", file, strerror(errno)); exit(127); } + close(1); + dup(outfd); + close(outfd); + argc -= 2; + } + } + // Replace the current process with another process image. Process::Execute(argv[0], argc, argv);