eval and execute: Changed how they work. Main difference is that eval returns the output of the function while execute merges the parent process's and child process's stdstreams

This commit is contained in:
Sekulum Forka 2021-05-11 10:27:40 +02:00
parent 36d2b8e03a
commit 4db9a4d831
1 changed files with 11 additions and 7 deletions

View File

@ -146,18 +146,22 @@ proc parseCommand(cmd: string): seq[string] =
else: newitem.add(c)
# executes executes the command. For now it involves catting the command and printing it
proc execute(cmd: seq[string]): string =
let progname=cmd[0]
let args = cmd[1..cmd.high]
let ps = startProcess(progname, args=args, options={poUsePath})
result=ps.outputStream.readAll
proc execute(cmd: string): int =
let parsed = cmd.parseCommand
let progname = parsed[0]
let args = parsed[1..parsed.high]
let ps = startProcess(progname, args=args, options={poUsePath, poParentStreams})
result = ps.waitForExit
ps.close
# eval evaluates the given string
proc eval(cmd: string): string =
let parsed = cmd.parseCommand
result = parsed.execute
let progname=parsed[0]
let args = parsed[1..parsed.high]
let ps = startProcess(progname, args=args, options={poUsePath})
result=ps.outputStream.readAll
ps.close
when isMainModule:
let stdinstrm = stdin.newFileStream