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:
parent
36d2b8e03a
commit
4db9a4d831
18
src/fsh.nim
18
src/fsh.nim
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue