summaryrefslogtreecommitdiff
path: root/vish.py
diff options
context:
space:
mode:
Diffstat (limited to 'vish.py')
-rwxr-xr-xvish.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/vish.py b/vish.py
index ec601a0..608a8b4 100755
--- a/vish.py
+++ b/vish.py
@@ -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)