The shell now supports sending stdout to a file.

This commit is contained in:
Jonas 'Sortie' Termansen 2011-11-24 17:42:40 +01:00
parent 724305f3a7
commit 63b622a086
1 changed files with 15 additions and 0 deletions

View File

@ -4,6 +4,7 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <libmaxsi/platform.h>
#include <libmaxsi/process.h>
#include <libmaxsi/sortix-keyboard.h>
@ -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);