diff options
-rwxr-xr-x | vish.py | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -3,6 +3,7 @@ import os import re import argparse +import sys IFS = (" ", "\t", "\n") @@ -29,14 +30,23 @@ class Pipeline(): class Instruction(): - def __init__(self, tokens: list=[]): + def __init__(self, tokens: list=[], stdout=None, stderr=None): self.prog = tokens[0] self.args = tokens[1:] + self.stdout = stdout + self.stderr = stderr def execute(self): cpid = os.fork() if cpid == 0: + if self.stdout is not None: + fd = os.open(self.stdout, os.O_WRONLY) + os.dup2(sys.stdout.fileno(), fd) + if self.stderr is not None: + fd = os.open(self.stderr, os.O_WRONLY) + os.dup2(sys.stderr.fileno(), fd) + os.execvp(self.prog, [self.prog] + self.args) else: os.waitpid(cpid, 0) |