Eval / execute: Raise a ShellCommandError if command is not available
This commit is contained in:
parent
ad3568d785
commit
adf612effd
22
src/fsh.nim
22
src/fsh.nim
|
@ -274,9 +274,14 @@ proc execute(cmd: string): int =
|
|||
stdout.write(runBuiltin(progname, args))
|
||||
result = 0
|
||||
continue
|
||||
let ps = startProcess(progname, args=args, options={poUsePath, poParentStreams})
|
||||
result = ps.waitForExit
|
||||
ps.close
|
||||
try:
|
||||
let ps = startProcess(progname, args=args, options={poUsePath, poParentStreams})
|
||||
result = ps.waitForExit
|
||||
ps.close
|
||||
except OSError as e:
|
||||
var e = newException(ShellCommandError, progname & ": command not found")
|
||||
e.command = progname
|
||||
raise e
|
||||
strm.close
|
||||
|
||||
# eval evaluates the given string
|
||||
|
@ -291,9 +296,14 @@ proc eval(cmd: string): string =
|
|||
if progname in builtins:
|
||||
result = runBuiltin(progname, args)
|
||||
continue
|
||||
let ps = startProcess(progname, args=args, options={poUsePath})
|
||||
result=ps.outputStream.readAll
|
||||
ps.close
|
||||
try:
|
||||
let ps = startProcess(progname, args=args, options={poUsePath})
|
||||
result=ps.outputStream.readAll
|
||||
ps.close
|
||||
except OSError as e:
|
||||
var e = newException(ShellCommandError, progname & ": Command not found")
|
||||
e.command=progname
|
||||
raise e
|
||||
strm.close
|
||||
|
||||
when isMainModule:
|
||||
|
|
Loading…
Reference in New Issue