Question about Process.run and system variables

Hello, I have a question because I didn’t found an answer. I would like to use Process.run to exec a make command, but I would like before the make command to change a global variable, the DESTDIR variable, how can I do that with Process.run ?

For example to have the same result as the bash command: DESTDIR=/temp/tempdir make install

Actually I have a function doing something like that:

def makeSource(arguments : Array(String), path = String.new)
            process = Process.run("make",   args: arguments,
                                            output: :inherit,
                                            error: :inherit,
                                            chdir:  Ism.settings.sourcesPath + "/" + 
                                                    @information.versionName + "/" +
                                                    @mainSourceDirectoryName + "/" +
                                                    path)
            if !process.success?
                Ism.notifyOfMakeError(path)
                exit 1
            end
        end

But I would like to add the possibility to override the DESTDIR variable

Process.run has an env parameter you can use to set it.

Something like:

Process.run "make", env: {"DESTDIR" => "/temp/tempdir"}, ...

ref: Process - Crystal 1.6.2

1 Like