diff options
| author | ruki <[email protected]> | 2020-12-05 00:15:52 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-12-05 00:15:52 +0800 |
| commit | 026fcce91e056d53cfeb1abe87c11c6548908bce (patch) | |
| tree | 46a586bd568140298d1b78f216c8c67b70cfcd3e /xmake/core/base/process.lua | |
| parent | 3ccbf254fd5a0013dfc91e272d47c74dd6ebd181 (diff) | |
support stdin for os.execv
Diffstat (limited to 'xmake/core/base/process.lua')
| -rw-r--r-- | xmake/core/base/process.lua | 32 |
1 files changed, 28 insertions, 4 deletions
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 |
