First some background about me: I started to use Nim only recently. It looks very interesting. :-) My programming experience of the last 20 years is mostly Python (wrote a book and several articles, and gave about 15 talks), but I also programmed in compiled languages, e. g. Pascal, C++ and Fortran. I'm working almost exclusively on Linux.
My current problem is this:
I want to run an external process, with the following conditions:
Now, looking through the documentation https://nim-lang.org/docs/osproc.html my understanding is
I saw the source code of execCmdEx at https://github.com/nim-lang/Nim/blob/master/lib/pure/osproc.nim#L1314 and would probably be able to apply this for my usecase. On the other hand, I imagine it should be simpler to achieve what I want with the standard library and wonder if I'm missing something. What do you recommend?
I would adapt execCmdEx for your purpose:
proc myExec(command, wd: string): tuple[output: string, exitCode: int] =
var p = startProcess(command, workingDir = wd, options = {poStdErrToStdOut})
var outp = outputStream(p)
close inputStream(p)
result = ("", -1)
var line = newStringOfCap(120).TaintedString
while true:
if outp.readLine(line):
result[0].string.add(line.string)
result[0].string.add("\n")
else:
result[1] = peekExitCode(p)
if result[1] != -1: break
close(p)
@juancarlospaco Thanks!
firejail seems to do much more than I want, and from reading a bit about the Nim package and the underlying library, I must admit that I don't even understand how I would apply it to my usecase. I only want to call the external process from a small command line program. (That said, my program won't be executed by the user directly, but implicitly from another program the user runs. I can elaborate on this if you're interested.)