René's URL Explorer Experiment


Title: Newer API · Issue #3 · pnappa/subprocesscpp · GitHub

Open Graph Title: Newer API · Issue #3 · pnappa/subprocesscpp

X Title: Newer API · Issue #3 · pnappa/subprocesscpp

Description: Our current API is a bit clunky and doesn't allow supporting all of the proposed features we wanted. So, here's some newer endpoints I propose: Executing a basic subprocess /** * Execute a subprocess and optionally call a function per li...

Open Graph Description: Our current API is a bit clunky and doesn't allow supporting all of the proposed features we wanted. So, here's some newer endpoints I propose: Executing a basic subprocess /** * Execute a subproce...

X Description: Our current API is a bit clunky and doesn't allow supporting all of the proposed features we wanted. So, here's some newer endpoints I propose: Executing a basic subprocess /** * Execute a ...

Opengraph URL: https://github.com/pnappa/subprocesscpp/issues/3

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Newer API","articleBody":"Our current API is a bit clunky and doesn't allow supporting all of the proposed features we wanted.\r\n\r\nSo, here's some newer endpoints I propose:\r\n\r\n\r\n### Executing a basic subprocess\r\n```c++\r\n/**\r\n * Execute a subprocess and optionally call a function per line of stdout.\r\n * @param commandPath   - the path of the executable to execute, e.g. \"/bin/cat\"\r\n * @param commandArgs   - the extra arguments for an executable e.g. {\"argument 1\", \"henlo\"}\r\n * @param stdinInput    - a list of inputs that will be piped into the processes' stdin\r\n * @param lambda        - a function that is called with every line from the executed process (default NOP function)\r\n * @param env           - a list of environment variables that the process will execute with (default nothing)\r\n */\r\nint execute(const std::string\u0026 commandPath, const std::vector\u003cstd::string\u003e\u0026 commandArgs, const std::vector\u003cstd::string\u003e\u0026 stdinInput, const std::function\u003cvoid(std::string)\u003e\u0026 lambda = [](std::string){}, const std::vector\u003cstd::string\u003e\u0026 env = {});\r\n```\r\nAlso, another `execute` function will exist, except that instead of taking in a std::vector to supply its stdin, it takes two input iterators (the start and end of a range). It's signature would look like this:\r\n```c++\r\ntemplate\u003cclass InputIt\u003e\r\nint execute(const std::string\u0026 commandPath, const std::vector\u003cstd::string\u003e\u0026 commandArgs, InputIt stdioBegin, InputIt stdioEnd, const std::function\u003cvoid(std::string)\u003e\u0026 lambda = [](std::string){}, const std::vector\u003cstd::string\u003e\u0026 env)\r\n```\r\nWhere the InputIt would require typical iterator methods implemented (similar to InputIterator defined here: https://en.cppreference.com/w/cpp/named_req/InputIterator).\r\n\r\n### Retrieving subprocess output\r\nSimilar to the `execute` function's parameters, the `check_output` function (name TBD, this name is just copied from the python3 subprocess library, we should check if they have better names (or there's internal conflict about how shit that name is)) simply returns a vector containing all lines of stdout.\r\n\r\n```c++\r\nstd::vector\u003cstd::string\u003e check_output(const std::string\u0026 commandPath, const std::vector\u003cstd::string\u003e\u0026 commandArgs, const std::vector\u003cstd::string\u003e\u0026 stdioInput, const std::vector\u003cstd::string\u003e\u0026 env= {})\r\ntemplate\u003cclass InputIt\u003e\r\nstd::vector\u003cstd::string\u003e check_output(const std::string\u0026 commandPath, const std::vector\u003cstd::string\u003e\u0026 commandArgs, InputIt stdioBegin, InputIt stdioEnd, const std::vector\u003cstd::string\u003e\u0026 env = {});\r\n```\r\n\r\nInput iterator is similar to the above restrictions in the `execute` function.\r\n\r\n### Interactive input/output\r\nTo enable dynamically setting what should be fed into the program based on the output, we introduce a newer ProcessStream class. This class has only a few methods available, but allows feeding a string into the process, and checking whether a line is available to read (there may not be one always available for each stdin, consider grep when the line doesn't match) and also extracting it. \r\n\r\nI imagine it's use will be something along these lines:\r\n```c++\r\n// ctor\r\nProcessStream(const std::string\u0026 commandPath, const std::vector\u003cstd::string\u003e\u0026 commandArgs, const std::vector\u003cstd::string\u003e\u0026 env);\r\n\r\nProcessStream ps(\"/bin/cat\", {});\r\n\r\nps \u003c\u003c \"henlo world\\n\";\r\n\r\nif (ps.ready()) {\r\n    std::string output;\r\n    output \u003c\u003c ps;\r\n    std::cout \u003c\u003c output;\r\n}\r\n```\r\n\r\nThere will naturally be non-operator overload equivalents to those endpoints (most likely something like `.write(std::string)` and `std::string .read(timeout)`.\r\n\r\nWe require a timeout, because it's not really possible to check if there *is* a line available, without some kind of call to select (I think!).\r\n\r\n### Daemon spawning\r\nPeople seem to like to spawn and forget processes (especially in some kind of management application), so providing a method to disown and mark them as daemons makes a whole lotta sense. I haven't written daemon code too often (it's been a couple years since I have I reckon), and that was in pure C. As this library *has to use C* to implement these features it's certainly doable, but would require different behaviour per OS, because this I imagine heavily differs between OSes. The problem is, I don't really know what a nice interface to doing so would be.\r\n\r\nAny suggestions would be much appreciated.\r\n\r\n### Error Handling\r\nAs we're dealing with external applications, they may throw at any time and inconsistently (either due to the application, the OS/user killing them, or bugs), we need some kind of error handling.\r\n\r\nCurrently, the above APIs proposed return an error status, but I feel like this may not be very idiomatic, and that exceptions should be used instead. I suppose this requires a read up on C++ philosophy before being able to make a decision, but I'm thinking of mirroring how Python's subprocess library does it, which is pretty much to throw an exception whenever anything goes wrong, including non-zero return statuses.\r\n\r\n\r\n### Asynchronous Calls\r\nWhether the user should be responsible for running this stuff in the background is again another philosophical question to ask, but as this is a library aimed at dumb-dumbs, its worth consideration if this is something we should hold their hand on. Currently, we provide a method to spawn a subprocess asynchronously, and return a `std::future` of the return code. Naturally, if we change the error handling to be a different strategy, this may not make sense, but I can't imagine asynchronous informing the main process about the status via exceptions can't be neat, so using futures on the return value seems like a good idea to cover this.\r\n\r\n### Final remarks\r\nIn my mind, these cover the current TODOs I propose in the current README, so it seems like a good direction to head. The only thing that I don't know and could cause problems in these interfaces is how Windows deals with processes. Some of these things may not be possible.\r\n\r\nAny comments are appreciated (and likely only Cameron is gonna comment, but I'll try and hook some people to comment).\r\n\r\nCheers","author":{"url":"https://github.com/pnappa","@type":"Person","name":"pnappa"},"datePublished":"2018-11-17T10:54:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":22},"url":"https://github.com/3/subprocesscpp/issues/3"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:fd1e3ebc-4cfd-716d-6f3d-68cfeb85dfc6
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC034:14E269:61C0E:7D270:6990A3DD
html-safe-nonce0a253ccbf441caf593465d6d232ed11c49d5c05b796504db25708dd7335ac0d2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMDM0OjE0RTI2OTo2MUMwRTo3RDI3MDo2OTkwQTNERCIsInZpc2l0b3JfaWQiOiIxMzk2ODk3NjQzMzE4MjU2NjA1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacf6c49160aa7362a66ffb008f3f29e92fad6159ac4eb4dc818c90e730a62bd3b0
hovercard-subject-tagissue:381851949
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pnappa/subprocesscpp/3/issue_layout
twitter:imagehttps://opengraph.githubassets.com/0d4efc9a247258a9d25e028f287aa4236723474873e63a3bd1e3d59cabd4a236/pnappa/subprocesscpp/issues/3
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/0d4efc9a247258a9d25e028f287aa4236723474873e63a3bd1e3d59cabd4a236/pnappa/subprocesscpp/issues/3
og:image:altOur current API is a bit clunky and doesn't allow supporting all of the proposed features we wanted. So, here's some newer endpoints I propose: Executing a basic subprocess /** * Execute a subproce...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamepnappa
hostnamegithub.com
expected-hostnamegithub.com
None42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b
turbo-cache-controlno-preview
go-importgithub.com/pnappa/subprocesscpp git https://github.com/pnappa/subprocesscpp.git
octolytics-dimension-user_id1394161
octolytics-dimension-user_loginpnappa
octolytics-dimension-repository_id156982630
octolytics-dimension-repository_nwopnappa/subprocesscpp
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id156982630
octolytics-dimension-repository_network_root_nwopnappa/subprocesscpp
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release3b33c5aedc9808f45bc5fcf0b1e4404cf749dac7
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/pnappa/subprocesscpp/issues/3#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpnappa%2Fsubprocesscpp%2Fissues%2F3
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpnappa%2Fsubprocesscpp%2Fissues%2F3
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=pnappa%2Fsubprocesscpp
Reloadhttps://patch-diff.githubusercontent.com/pnappa/subprocesscpp/issues/3
Reloadhttps://patch-diff.githubusercontent.com/pnappa/subprocesscpp/issues/3
Reloadhttps://patch-diff.githubusercontent.com/pnappa/subprocesscpp/issues/3
pnappa https://patch-diff.githubusercontent.com/pnappa
subprocesscpphttps://patch-diff.githubusercontent.com/pnappa/subprocesscpp
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fpnappa%2Fsubprocesscpp
Fork 1 https://patch-diff.githubusercontent.com/login?return_to=%2Fpnappa%2Fsubprocesscpp
Star 5 https://patch-diff.githubusercontent.com/login?return_to=%2Fpnappa%2Fsubprocesscpp
Code https://patch-diff.githubusercontent.com/pnappa/subprocesscpp
Issues 1 https://patch-diff.githubusercontent.com/pnappa/subprocesscpp/issues
Pull requests 1 https://patch-diff.githubusercontent.com/pnappa/subprocesscpp/pulls
Actions https://patch-diff.githubusercontent.com/pnappa/subprocesscpp/actions
Projects 0 https://patch-diff.githubusercontent.com/pnappa/subprocesscpp/projects
Security 0 https://patch-diff.githubusercontent.com/pnappa/subprocesscpp/security
Insights https://patch-diff.githubusercontent.com/pnappa/subprocesscpp/pulse
Code https://patch-diff.githubusercontent.com/pnappa/subprocesscpp
Issues https://patch-diff.githubusercontent.com/pnappa/subprocesscpp/issues
Pull requests https://patch-diff.githubusercontent.com/pnappa/subprocesscpp/pulls
Actions https://patch-diff.githubusercontent.com/pnappa/subprocesscpp/actions
Projects https://patch-diff.githubusercontent.com/pnappa/subprocesscpp/projects
Security https://patch-diff.githubusercontent.com/pnappa/subprocesscpp/security
Insights https://patch-diff.githubusercontent.com/pnappa/subprocesscpp/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/pnappa/subprocesscpp/issues/3
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/pnappa/subprocesscpp/issues/3
Newer APIhttps://patch-diff.githubusercontent.com/pnappa/subprocesscpp/issues/3#top
https://github.com/pnappa
https://github.com/pnappa
pnappahttps://github.com/pnappa
on Nov 17, 2018https://github.com/pnappa/subprocesscpp/issues/3#issue-381851949
https://en.cppreference.com/w/cpp/named_req/InputIteratorhttps://en.cppreference.com/w/cpp/named_req/InputIterator
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.