Comments (3)
Work in progress at https://github.com/shawnw/subprocess/tree/async_promises
(At the moment just uses futures for waiting for processes to exit in command::run()
.
from subprocess.
(Continued from reddit)
For asynchronous command execution, there's two scenarios to consider.
First, running a command in the background with one or more of its stdin/stdout/stderr connected to an iostream. Might be worth looking into Boost.Process's pipe streams and buffers as an example of a fairly lightweight way to provide such streams. You still need a way to get a command's exit status when it finishes running (Just getting EOF on a pipe isn't enough).
Second, the case where you just want to capture the output in a string. My idea for this (Which can also be used for the exit status of the first case and possibly even in executing pipelines of multiple commands) is to have a run_async()
method that returns a future that, when complete, gives you an object with the captured stdout/stderr (If any), exit status, etc.
It'd look something like
std::future<result> status = command.run_async();
while (status.wait_for(std::chrono::seconds::zero) != std::future::ready) {
// Do something else
}
auto res = status.get();
std::cout << res.stdout() << '\n';
from subprocess.
As you are designing the async API, here are a few thoughts that came up:
- Long-running pipes will delay the final result and in realtime applications, users are often interested in processing chunks of data as they flow in. It would be nice to have something like a
span<const byte>
orstring_view
abstraction to process data as it arrives, e.g., in 64k blocks. - From a dependency perspective, a hard requirement on Boost would rule us out as user. If you go down the Boost.Process route, it would be great to keep it optional.
from subprocess.
Related Issues (14)
- Support shell-like tokenization HOT 2
- Add support for setting options and exporting environment variables
- Redirection operators don't quite work like shell. HOT 1
- File descriptors are opened during command creation HOT 3
- Allow output capture into a stream
- Add support for windows
- Support && and || HOT 1
- Make the library header only HOT 1
- Use posix_spawnp() instead of fork()/exec() HOT 1
- Robust integration testing HOT 1
- Support for C++14/C++11
- posix_process reads stdout before stderr
- Error in the documention
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 subprocess.