Comments (8)
yeah it works greatly thanks for this beautiful project.
Happy new year.
from cpp-subprocess.
#include <subprocess.hpp>
using namespace std;
using namespace subprocess;
int main()
{
auto p = Popen({"cat", "-"}, input{PIPE}, output{"cat_fredirect.txt"});
auto msg = "through stdin to stdout";
p.send(msg, strlen(msg));
p.wait();
}
i tried the code in the readme.md and it still waits forever. Haalp!
from cpp-subprocess.
I made detail::Streams stream_
public
and reset()
it after send()
and it worked!
for ( int i = 0 ; i < 5 ; i++ )
{
sub_processes.emplace_back(Popen({"cat", "-"},input{PIPE}));
sub_processes[i].send("3 5\n", 5);
sub_processes[i].stream_.input_.reset();
}
from cpp-subprocess.
You didn't have to make "stream_" public for this.
You could have instead done:
fclose(sub_processes[i].input());
from cpp-subprocess.
Hi @arun11299
first of all nice profile picture :D
secondly, i used that line instead of resetting the shared ptr and it did crash the program.
after going out of scope the default constructor was called and it tried to delete the shared ptr which was already deleted as a raw ptr using fclose().
is there something i am missing here?
from cpp-subprocess.
Ah..ofcourse. I will provide an API to fix it. Thanks :)
from cpp-subprocess.
i am looking forward to that. have a nice day
from cpp-subprocess.
I have added this test.
void test_cat_send_terminate()
{
std::cout << "Test::test_cat_send_terminate" << std::endl;
std::vector<sp::Popen> pops;
for (int i=0; i < 5; i++) {
pops.emplace_back(sp::Popen({"cat", "-"}, sp::input{sp::PIPE}));
pops[i].send("3 5\n", 5);
pops[i].close_input();
}
for (int i=0; i < 5; i++) {
pops[i].wait();
}
std::cout << "END_TEST" << std::endl;
}
Let me know if it works for you.
And, Happy new year!!
from cpp-subprocess.
Related Issues (20)
- How to communicate with interactive shell script? HOT 1
- memory leak HOT 2
- execute_child shouldn't use any signal-unsafe functions
- string comparison issue on win32 HOT 1
- Thread safety? HOT 2
- missing inline in three MSVC specific functions HOT 1
- MinGW support HOT 1
- Windows support for environment variables HOT 2
- add option to redirect output to stdout
- [Question] Why delete operator= for the Streams class? HOT 4
- Blocking when using read_all with socket stream
- Busy looping when waiting for subprocess to finish HOT 1
- Conan support HOT 1
- wait() / communicate() can hang indefinitely with no recourse
- Popen blocking on Windows HOT 2
- Support CPM / cmake
- Compare with similar/related libraries HOT 2
- question: condition for `communicate_threaded` HOT 1
- Some windows errors HOT 1
- Issue with quotes on windows HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpp-subprocess.