subprocess
简介
子进程管理模块
组件接口
subprocess.gs
| 函数原型 | 函数作用 | 
|---|---|
| object spawn(array argv, map opt_args = nil) | 创建子进程 | 
| array shell_exec(string cmd, string cwd = nil) | 通过shell环境执行命令,并且将完整的输出以字符串的方式返回。 | 
SubProcessObject.gs
子进程对象
| 函数原型 | 函数作用 | 
|---|---|
| int get_pid() | 获取子进程ID | 
| bool write_stdin(buffer data) | 与子进程交互,将数据发送到stdin | 
| buffer read_stdout(int size) | 从stdout读取数据 | 
| buffer read_stderr(int size) | 从stderr读取数据 | 
| void terminate() | 终止子进程 | 
| void kill() | 杀死子进程 | 
| bool alive() | 检查子进程是否存活 | 
| int join() | 等待子进程结束,并返回子进程的返回值 | 
枚举
StdioOptions
| 枚举成员 | 值 | 描述 | 
|---|---|---|
| NONE | ||
| PIPE | ||
| STDOUT | 
样例
void main()
{
    object process = subprocess.spawn(["ls", "-l"], {
        "stdout": StdioOptions.PIPE,
    });
    printf("pid: %d\n", process.get_pid());
    printf("stdout: %O\n", process.read_stdout(4096).to_string());
}