dl
dl_process.h
浏览该文件的文档.
1
11#pragma once
12
13#include <string>
14
15#include "system/dl_thread.h"
16#include "base/dl_list_mt.h"
17
18namespace subprocess
19{
20 class Popen;
21}
22
23namespace dl
24{
27{
28public:
29 enum class State
30 {
31 NONE, // 空
32 START, // 开始准备
33 RUN, // 正在执行
34 END // 执行完成
35 };
36 // 调用结果
37 struct Result
38 {
40 std::string _str;
41 };
42 // 异步调用
44 {
45 friend class Process;
46 public:
48 std::string GetOutput()
49 {
50 std::lock_guard guard{ _mutexRet };
51 return _result._str;
52 }
53
55 {
56 return _listLine;
57 }
59 _thread{ nullptr },
60 _p{ nullptr },
61 _bEnd{ false }
62 {
63 }
65 private:
66 Thread* _thread;
67 subprocess::Popen* _p;
68 std::vector<std::string> _cmd;
69 bool _bEnd;
70 std::mutex _mutexRet;
71 Result _result;
73 };
74
75 // 阻塞调用
76 static bool Exec(const std::vector<std::string>& cmd, Result& result);
77
78 // 异步调用
79 static bool ExecMulti(const std::vector<std::string>& cmd, Instance& instance);
80
81
82
83 static void Send(Instance& instance, std::string_view str);
84private:
85 static void _thread_exec(void* p);
86
87
88 static std::string _read(Instance& instance);
89};
90}
std::string GetOutput()
返回所有输出
ListMultiThread< std::string > & GetOutputLine()
按行返回(不包含换行符)
系统进程
static bool ExecMulti(const std::vector< std::string > &cmd, Instance &instance)
static bool Exec(const std::vector< std::string > &cmd, Result &result)
static void Send(Instance &instance, std::string_view str)
多线程队列
线程封装