Eval / execute: Raise a ShellCommandError if command is not available

This commit is contained in:
Sekulum Forka 2021-05-13 14:17:12 +02:00
parent ad3568d785
commit adf612effd
1 changed files with 16 additions and 6 deletions

View File

@ -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: