mirror of https://gitlab.com/cppit/jucipp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
51 lines
1.5 KiB
|
10 years ago
|
#include "process.hpp"
|
||
|
8 years ago
|
#include <glib.h>
|
||
|
10 years ago
|
|
||
|
|
int main() {
|
||
|
8 years ago
|
auto output = std::make_shared<std::string>();
|
||
|
|
auto error = std::make_shared<std::string>();
|
||
|
10 years ago
|
{
|
||
|
9 years ago
|
TinyProcessLib::Process process("echo Test", "", [output](const char *bytes, size_t n) {
|
||
|
8 years ago
|
*output += std::string(bytes, n);
|
||
|
10 years ago
|
});
|
||
|
8 years ago
|
g_assert(process.get_exit_status() == 0);
|
||
|
|
g_assert(output->substr(0, 4) == "Test");
|
||
|
10 years ago
|
output->clear();
|
||
|
|
}
|
||
|
8 years ago
|
|
||
|
10 years ago
|
{
|
||
|
9 years ago
|
TinyProcessLib::Process process("echo Test && ls an_incorrect_path", "", [output](const char *bytes, size_t n) {
|
||
|
8 years ago
|
*output += std::string(bytes, n);
|
||
|
10 years ago
|
}, [error](const char *bytes, size_t n) {
|
||
|
8 years ago
|
*error += std::string(bytes, n);
|
||
|
10 years ago
|
});
|
||
|
8 years ago
|
g_assert(process.get_exit_status() > 0);
|
||
|
|
g_assert(output->substr(0, 4) == "Test");
|
||
|
10 years ago
|
g_assert(!error->empty());
|
||
|
|
output->clear();
|
||
|
|
error->clear();
|
||
|
|
}
|
||
|
8 years ago
|
|
||
|
10 years ago
|
{
|
||
|
9 years ago
|
TinyProcessLib::Process process("bash", "", [output](const char *bytes, size_t n) {
|
||
|
8 years ago
|
*output += std::string(bytes, n);
|
||
|
10 years ago
|
}, nullptr, true);
|
||
|
|
process.write("echo Test\n");
|
||
|
|
process.write("exit\n");
|
||
|
8 years ago
|
g_assert(process.get_exit_status() == 0);
|
||
|
|
g_assert(output->substr(0, 4) == "Test");
|
||
|
10 years ago
|
output->clear();
|
||
|
|
}
|
||
|
8 years ago
|
|
||
|
10 years ago
|
{
|
||
|
9 years ago
|
TinyProcessLib::Process process("cat", "", [output](const char *bytes, size_t n) {
|
||
|
8 years ago
|
*output += std::string(bytes, n);
|
||
|
10 years ago
|
}, nullptr, true);
|
||
|
|
process.write("Test\n");
|
||
|
|
process.close_stdin();
|
||
|
8 years ago
|
g_assert(process.get_exit_status() == 0);
|
||
|
|
g_assert(output->substr(0, 4) == "Test");
|
||
|
10 years ago
|
output->clear();
|
||
|
|
}
|
||
|
|
}
|