key: os.execv name: os.execv api: bool, string os.execv(string cmd, table args[, table opt]) version: 2.1.5
Similar to ${link os.exec}, just the way to pass parameters is passed through the parameter list, not the string command, for example:
${link os.execv}("echo", {"hello", "xmake!"})
In addition, this interface also supports an optional parameter for passing settings: redirect output, perform environment variable settings, for example:
${link os.execv}("echo", {"hello", "xmake!"}, {stdout = outfile, stderr = errfile, envs = {PATH = "xxx;xx", CFLAGS = "xx"}})
Valid fields for opt are:
bool try, default value: falsestring shelltable envstable setenvstable addenvsfilepath/file/pipe stdinfilepath/file/pipe stdoutfilepath/file/pipe stderrbool detatch, default value: falsebool exclusive, default value: falseSet try to true to return the errors instead of raising them.
local ok, errors = ${link os.execv}("echo", {"hello", "xmake!"}, {try = true})
Among them, the stdout and stderr parameters are used to pass redirected output and error output. You can directly pass in the file path or the file object opened by ${link io.open}.
After v2.5.1, we also support setting the stdin parameter to support redirecting input files.
!> stdout/stderr/stdin can simultaneously support three types of values: file path, file object, and pipe object.
In addition, if you want to temporarily set and rewrite some environment variables during this execution, you can pass the envs parameter. The environment variable settings inside will replace the existing settings, but will not affect the outer execution environment, only the current command.
We can also get all the current environment variables through the ${link os.getenvs}() interface, and then pass in the envs parameter after rewriting some parts.