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.4 KiB
51 lines
1.4 KiB
|
10 years ago
|
#include <glib.h>
|
||
|
|
#include "process.hpp"
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
auto output=std::make_shared<std::string>();
|
||
|
|
auto error=std::make_shared<std::string>();
|
||
|
|
{
|
||
|
|
Process process("echo Test", "", [output](const char *bytes, size_t n) {
|
||
|
|
*output+=std::string(bytes, n);
|
||
|
|
});
|
||
|
|
g_assert(process.get_exit_status()==0);
|
||
|
|
g_assert(output->substr(0, 4)=="Test");
|
||
|
|
output->clear();
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
Process process("echo Test && ls an_incorrect_path", "", [output](const char *bytes, size_t n) {
|
||
|
|
*output+=std::string(bytes, n);
|
||
|
|
}, [error](const char *bytes, size_t n) {
|
||
|
|
*error+=std::string(bytes, n);
|
||
|
|
});
|
||
|
|
g_assert(process.get_exit_status()>0);
|
||
|
|
g_assert(output->substr(0, 4)=="Test");
|
||
|
|
g_assert(!error->empty());
|
||
|
|
output->clear();
|
||
|
|
error->clear();
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
Process process("bash", "", [output](const char *bytes, size_t n) {
|
||
|
|
*output+=std::string(bytes, n);
|
||
|
|
}, nullptr, true);
|
||
|
|
process.write("echo Test\n");
|
||
|
|
process.write("exit\n");
|
||
|
|
g_assert(process.get_exit_status()==0);
|
||
|
|
g_assert(output->substr(0, 4)=="Test");
|
||
|
|
output->clear();
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
Process process("cat", "", [output](const char *bytes, size_t n) {
|
||
|
|
*output+=std::string(bytes, n);
|
||
|
|
}, nullptr, true);
|
||
|
|
process.write("Test\n");
|
||
|
|
process.close_stdin();
|
||
|
|
g_assert(process.get_exit_status()==0);
|
||
|
|
g_assert(output->substr(0, 4)=="Test");
|
||
|
|
output->clear();
|
||
|
|
}
|
||
|
|
}
|