mirror of
https://github.com/arun11299/cpp-subprocess.git
synced 2025-08-05 04:46:21 -04:00
This reverts commit 5d92f4849276aa313dc1ba56c1556f4cca27fc7f.
This commit is contained in:
parent
5d92f48492
commit
871577770a
@ -1 +0,0 @@
|
||||
BreakBeforeBraces: Stroustrup
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
build*
|
||||
.vscode
|
@ -1,6 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.9)
|
||||
|
||||
project(subprocess CXX)
|
||||
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
821
subprocess.hpp
821
subprocess.hpp
File diff suppressed because it is too large
Load Diff
@ -1,8 +0,0 @@
|
||||
|
||||
|
||||
add_executable(test_subprocess test_subprocess.cc)
|
||||
|
||||
add_test(
|
||||
NAME test_subprocess
|
||||
COMMAND $<TARGET_FILE:test_subprocess>
|
||||
)
|
@ -1,27 +1,19 @@
|
||||
#include "../subprocess.hpp"
|
||||
#include <iostream>
|
||||
#include "../subprocess.hpp"
|
||||
|
||||
using namespace subprocess;
|
||||
|
||||
void test_exename()
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
auto ret = call({"--version"}, executable{"cmake"}, shell{false});
|
||||
#else
|
||||
auto ret = call({"-l"}, executable{"ls"}, shell{false});
|
||||
#endif
|
||||
std::cout << ret << std::endl;
|
||||
}
|
||||
|
||||
void test_input()
|
||||
{
|
||||
#if 0
|
||||
auto p = Popen({"cmake", "--version"}, output{PIPE}, input{PIPE});
|
||||
#else
|
||||
auto p = Popen({"grep", "f"}, output{PIPE}, input{PIPE});
|
||||
const char *msg = "one\ntwo\nthree\nfour\nfive\n";
|
||||
const char* msg = "one\ntwo\nthree\nfour\nfive\n";
|
||||
p.send(msg, strlen(msg));
|
||||
#endif
|
||||
auto res = p.communicate(nullptr, 0);
|
||||
std::cout << res.first.buf.data() << std::endl;
|
||||
}
|
||||
@ -30,8 +22,7 @@ void test_piping()
|
||||
{
|
||||
auto cat = Popen({"cat", "../subprocess.hpp"}, output{PIPE});
|
||||
auto grep = Popen({"grep", "template"}, input{cat.output()}, output{PIPE});
|
||||
auto cut =
|
||||
Popen({"cut", "-d,", "-f", "1"}, input{grep.output()}, output{PIPE});
|
||||
auto cut = Popen({"cut", "-d,", "-f", "1"}, input{grep.output()}, output{PIPE});
|
||||
auto res = cut.communicate().first;
|
||||
std::cout << res.buf.data() << std::endl;
|
||||
}
|
||||
@ -54,10 +45,7 @@ void test_sleep()
|
||||
|
||||
while (p.poll() == -1) {
|
||||
std::cout << "Waiting..." << std::endl;
|
||||
#ifdef _MSC_VER
|
||||
#else
|
||||
sleep(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::cout << "Sleep ended: ret code = " << p.retcode() << std::endl;
|
||||
@ -68,7 +56,7 @@ void test_read_all()
|
||||
Popen p = Popen({"echo","12345678"}, output{PIPE});
|
||||
|
||||
std::vector<char> buf(6);
|
||||
int rbytes = util::read_all(p.output(), buf);
|
||||
int rbytes = util::read_all(fileno(p.output()), buf);
|
||||
|
||||
std::string out(buf.begin(), buf.end());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user