-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPopenSystemCommand.cpp
More file actions
47 lines (41 loc) · 2.11 KB
/
PopenSystemCommand.cpp
File metadata and controls
47 lines (41 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "stdafx.h"
#include "PopenSystemCommand.h"
#include <vector>
namespace cobaltfusion
{
PopenSystemCommand::PopenSystemCommand(const std::string& command)
: m_pipe(nullptr)
{
std::vector<char> line(128);
m_pipe = _popen(command.c_str(), "r");
while (0 == feof(m_pipe))
{
if (fgets(&line[0], static_cast<int>(line.size()), m_pipe) != nullptr)
{
m_output << std::string(&line[0]);
}
}
}
std::string PopenSystemCommand::GetOutput() const
{
return m_output.str();
}
std::pair<int, std::string> PopenSystemCommand::GetResult()
{
return std::make_pair(close(), m_output.str());
}
int PopenSystemCommand::close()
{
int result = 0;
if (m_pipe != nullptr)
{
result = _pclose(m_pipe);
m_pipe = nullptr;
}
return result;
}
PopenSystemCommand::~PopenSystemCommand()
{
close();
}
}