summaryrefslogtreecommitdiff
path: root/xmake/core/base
diff options
context:
space:
mode:
authorruki <[email protected]>2020-12-05 00:15:52 +0800
committerruki <[email protected]>2020-12-05 00:15:52 +0800
commit026fcce91e056d53cfeb1abe87c11c6548908bce (patch)
tree46a586bd568140298d1b78f216c8c67b70cfcd3e /xmake/core/base
parent3ccbf254fd5a0013dfc91e272d47c74dd6ebd181 (diff)
support stdin for os.execv
Diffstat (limited to 'xmake/core/base')
-rw-r--r--xmake/core/base/os.lua4
-rw-r--r--xmake/core/base/process.lua32
2 files changed, 30 insertions, 6 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 6923aaa0c..2442cea95 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -662,7 +662,7 @@ end
-- @param program "clang", "xcrun -sdk macosx clang", "~/dir/test\ xxx/clang"
-- filename "clang", "xcrun"", "~/dir/test\ xxx/clang"
-- @param argv the arguments
--- @param opt the options, e.g. {stdout = filepath/file/pipe, stderr = filepath/file/pipe,
+-- @param opt the options, e.g. {stdin = filepath/file/pipe, stdout = filepath/file/pipe, stderr = filepath/file/pipe,
-- envs = {PATH = "xxx;xx", CFLAGS = "xx"}}
--
function os.execv(program, argv, opt)
@@ -700,7 +700,7 @@ function os.execv(program, argv, opt)
end
-- init open options
- local openopt = {envs = envs, stdout = opt.stdout, stderr = opt.stderr, curdir = opt.curdir, detach = opt.detach}
+ local openopt = {envs = envs, stdin = opt.stdin, stdout = opt.stdout, stderr = opt.stderr, curdir = opt.curdir, detach = opt.detach}
-- open command
local ok = -1
diff --git a/xmake/core/base/process.lua b/xmake/core/base/process.lua
index 40755d6ef..23a3882f4 100644
--- a/xmake/core/base/process.lua
+++ b/xmake/core/base/process.lua
@@ -163,14 +163,26 @@ end
-- open a subprocess
--
-- @param command the process command
--- @param opt the option arguments, e.g. {stdout = filepath/file/pipe, stderr = filepath/file/pipe, envs = {"PATH=xxx", "XXX=yyy"}})
+-- @param opt the option arguments, e.g. {stdin = filepath/file/pipe, stdout = filepath/file/pipe, stderr = filepath/file/pipe, envs = {"PATH=xxx", "XXX=yyy"}})
--
-- @return the subprocess
--
function process.open(command, opt)
- -- get stdout and pass to subprocess
+ -- get stdin and pass to subprocess
opt = opt or {}
+ local stdin = opt.stdin
+ if type(stdin) == "string" then
+ opt.inpath = stdin
+ elseif type(stdin) == "table" then
+ if stdin.otype and stdin:otype() == 2 then
+ opt.inpipe = stdin:cdata()
+ else
+ opt.infile = stdin:cdata()
+ end
+ end
+
+ -- get stdout and pass to subprocess
local stdout = opt.stdout
if type(stdout) == "string" then
opt.outpath = stdout
@@ -207,14 +219,26 @@ end
--
-- @param program the program
-- @param argv the arguments list
--- @param opt the option arguments, e.g. {stdout = filepath/file/pipe, stderr = filepath/file/pipe, envs = {"PATH=xxx", "XXX=yyy"}})
+-- @param opt the option arguments, e.g. {stdin = filepath/file/pipe, stdout = filepath/file/pipe, stderr = filepath/file/pipe, envs = {"PATH=xxx", "XXX=yyy"}})
--
-- @return the subprocess
--
function process.openv(program, argv, opt)
- -- get stdout and pass to subprocess
+ -- get stdin and pass to subprocess
opt = opt or {}
+ local stdin = opt.stdin
+ if type(stdin) == "string" then
+ opt.inpath = stdin
+ elseif type(stdin) == "table" then
+ if stdin.otype and stdin:otype() == 2 then
+ opt.inpipe = stdin:cdata()
+ else
+ opt.infile = stdin:cdata()
+ end
+ end
+
+ -- get stdout and pass to subprocess
local stdout = opt.stdout
if type(stdout) == "string" then
opt.outpath = stdout