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))
|
stdout.write(runBuiltin(progname, args))
|
||||||
result = 0
|
result = 0
|
||||||
continue
|
continue
|
||||||
let ps = startProcess(progname, args=args, options={poUsePath, poParentStreams})
|
try:
|
||||||
result = ps.waitForExit
|
let ps = startProcess(progname, args=args, options={poUsePath, poParentStreams})
|
||||||
ps.close
|
result = ps.waitForExit
|
||||||
|
ps.close
|
||||||
|
except OSError as e:
|
||||||
|
var e = newException(ShellCommandError, progname & ": command not found")
|
||||||
|
e.command = progname
|
||||||
|
raise e
|
||||||
strm.close
|
strm.close
|
||||||
|
|
||||||
# eval evaluates the given string
|
# eval evaluates the given string
|
||||||
|
@ -291,9 +296,14 @@ proc eval(cmd: string): string =
|
||||||
if progname in builtins:
|
if progname in builtins:
|
||||||
result = runBuiltin(progname, args)
|
result = runBuiltin(progname, args)
|
||||||
continue
|
continue
|
||||||
let ps = startProcess(progname, args=args, options={poUsePath})
|
try:
|
||||||
result=ps.outputStream.readAll
|
let ps = startProcess(progname, args=args, options={poUsePath})
|
||||||
ps.close
|
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
|
strm.close
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
|
|
Loading…
Reference in New Issue