summaryrefslogtreecommitdiff
path: root/core/src/xmake/process
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
parentccfe7ed01bd603f4435ce6463ecf267f49ddd6fe (diff)
improve to open process and support pipe
Diffstat (limited to 'core/src/xmake/process')
-rw-r--r--core/src/xmake/process/open.c32
-rw-r--r--core/src/xmake/process/openv.c46
2 files changed, 70 insertions, 8 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;
diff --git a/core/src/xmake/process/openv.c b/core/src/xmake/process/openv.c
index 5e0af8d9c..69557aa69 100644
--- a/core/src/xmake/process/openv.c
+++ b/core/src/xmake/process/openv.c
@@ -35,7 +35,9 @@
* implementation
*/
-// p = process.openv(shellname, argv, {outpath = "", errpath = "", outfile = , errfile = , envs = {"PATH=xxx", "XXX=yyy"})
+/* p = process.openv(shellname, argv,
+ * {outpath = "", errpath = "", outfile = , errfile = , outpipe = , errpipe, envs = {"PATH=xxx", "XXX=yyy"})
+ */
tb_int_t xm_process_openv(lua_State* lua)
{
// check
@@ -92,12 +94,14 @@ tb_int_t xm_process_openv(lua_State* lua)
tb_process_attr_t attr = {0};
// get option arguments
- tb_size_t envn = 0;
- tb_char_t const* envs[256] = {0};
- tb_char_t const* outpath = tb_null;
- tb_char_t const* errpath = tb_null;
- xm_io_file_t* outfile = tb_null;
- xm_io_file_t* errfile = tb_null;
+ tb_size_t envn = 0;
+ tb_char_t const* envs[256] = {0};
+ tb_char_t const* outpath = tb_null;
+ tb_char_t const* errpath = tb_null;
+ xm_io_file_t* outfile = tb_null;
+ xm_io_file_t* errfile = tb_null;
+ tb_pipe_file_ref_t outpipe = tb_null;
+ tb_pipe_file_ref_t errpipe = tb_null;
if (lua_istable(lua, 3))
{
// get outpath
@@ -130,6 +134,24 @@ tb_int_t xm_process_openv(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, 3);
@@ -190,6 +212,11 @@ tb_int_t xm_process_openv(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)
@@ -208,6 +235,11 @@ tb_int_t xm_process_openv(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;