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:

  * There may be untrusted arguments, so I want them escaped or better not use 
the shell at all.
  * I don't want to show the output (neither stdout nor stderr) on the screen, 
i. e. I don't want the option poParentStreams.
  * I want to wait until the program finishes.
  * After the program run, I want to check the return code and fail if it's not 
0.
  * (Although I don't need it right now, in other cases I might want the 
content of stdout and/or stderr as well.)



Now, looking through the documentation 
[https://nim-lang.org/docs/osproc.html](https://nim-lang.org/docs/osproc.html) 
my understanding is

  * execProcess takes a list of arguments and doesn't need a shell, but the 
function only returns a string and not the return code.
  * execCmd and execCmdEx take just a string and thus don't seem to deal with 
untrusted arguments.
  * startProcess looks flexible, but to wait for the program to exit, I need to 
call waitForExit. However, in this case the documentation says it may deadlock 
unless you use poParentStreams (which I don't want).



I saw the source code of execCmdEx at 
[https://github.com/nim-lang/Nim/blob/master/lib/pure/osproc.nim#L1314](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?

Reply via email to