(answer mostly copied from Call popen with environment)
There is an os.spawn
function in the ExtensionProposal API.
You can use it as follows:
require"ex"
local proc, err = os.spawn{
command = e.."/bin/aprogr",
args = {
"arg1",
"arg2",
-- etc
},
env = {
A = 100, -- I assume it tostrings the value
B = "Hi",
C = "Test",
},
-- you can also specify stdin, stdout, and stderr
-- see the proposal page for more info
}
if not proc then
error("Failed to aprogrinate! "..tostring(err))
end
-- if you want to wait for the process to finish:
local exitcode = proc:wait()
lua-ex-pai provides implementations for POSIX and Windows.
It allows the spawning of multiple concurrent processes.
You can find precompiled binaries of this implementation bundled with the LuaForWindows distribution.
Here is a more concise version of your use case:
require"ex"
local cmd1_out = io.pipe()
local cmd1_proc = assert(os.spawn("cmd", {
stdout = cmd1_out,
}))
local cmd2_out = io.pipe()
local cmd2_proc = assert(os.spawn("cmd", {
stdout = cmd1_out,
}))
-- perform actions with cmd1 and cmd2