summaryrefslogtreecommitdiff
path: root/core/src/xmake/process/open.c
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-03 22:51:06 +0800
committerruki <[email protected]>2020-02-07 22:45:56 +0800
commitcf9970fddd580f8b9bb8ed25d6d9cfa67a607b69 (patch)
tree57dda8e994431a59f96f44fec83d416fb4db0db6 /core/src/xmake/process/open.c
parentccfe7ed01bd603f4435ce6463ecf267f49ddd6fe (diff)
improve to open process and support pipe
Diffstat (limited to 'core/src/xmake/process/open.c')
-rw-r--r--core/src/xmake/process/open.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/core/src/xmake/process/open.c b/core/src/xmake/process/open.c
index 45892fefd..2f45b5c6f 100644
--- a/core/src/xmake/process/open.c
+++ b/core/src/xmake/process/open.c
@@ -35,7 +35,9 @@
* implementation
*/
-// p = process.open(command, {outpath = "", errpath = "", envs = {"PATH=xxx", "XXX=yyy"}})
+/* p = process.open(command,
+ * {outpath = "", errpath = "", outfile = "", errfile = "", outpipe = "", errpipe = "", envs = {"PATH=xxx", "XXX=yyy"}})
+ */
tb_int_t xm_process_open(lua_State* lua)
{
// check
@@ -88,6 +90,24 @@ tb_int_t xm_process_open(lua_State* lua)
lua_pop(lua, 1);
}
+ // get outpipe
+ if (!outpath && !outfile)
+ {
+ lua_pushstring(lua, "outpipe");
+ lua_gettable(lua, 3);
+ outpipe = (tb_pipe_file_ref_t)lua_touserdata(lua, -1);
+ lua_pop(lua, 1);
+ }
+
+ // get errpipe
+ if (!errpath && !errfile)
+ {
+ lua_pushstring(lua, "errpipe");
+ lua_gettable(lua, 3);
+ errpipe = (tb_pipe_file_ref_t)lua_touserdata(lua, -1);
+ lua_pop(lua, 1);
+ }
+
// get environments
lua_pushstring(lua, "envs");
lua_gettable(lua, 2);
@@ -148,6 +168,11 @@ tb_int_t xm_process_open(lua_State* lua)
attr.outtype = TB_PROCESS_REDIRECT_TYPE_FILE;
}
}
+ else if (outpipe)
+ {
+ attr.outpipe = outpipe;
+ attr.outtype = TB_PROCESS_REDIRECT_TYPE_PIPE;
+ }
// redirect stderr?
if (errpath)
@@ -166,6 +191,11 @@ tb_int_t xm_process_open(lua_State* lua)
attr.errtype = TB_PROCESS_REDIRECT_TYPE_FILE;
}
}
+ else if (errpipe)
+ {
+ attr.errpipe = errpipe;
+ attr.errtype = TB_PROCESS_REDIRECT_TYPE_PIPE;
+ }
// set the new environments
if (envn > 0) attr.envp = envs;