How to run external programs without GC allocations?

I’d like to run an external program in a code, that can be compiled with StaticCompiler.
There are e.g. Base.run(cmd /c dir) (I work in Windows) and Shell.run("dir"). However these commands need GC allocations. So they cannot be compiled statically.
Is it possible to run external programs without GC allocations?

On Linux you can use the function system(). You can call C function directly from Julia. No idea if that works with StaticCompiler.

#include <stdlib.h>
...
int status = system("./foo 1 2 3");

system() will wait for foo to complete execution, then return a status variable which you can use to check e.g. exitcode (the command’s exitcode gets multiplied by 256, so divide system()'s return value by that to get the actual exitcode: int exitcode = status / 256).

1 Like