{"id":13706706,"url":"https://github.com/lbartnik/subprocess","last_synced_at":"2025-05-05T23:31:24.336Z","repository":{"id":85002515,"uuid":"72962378","full_name":"lbartnik/subprocess","owner":"lbartnik","description":null,"archived":false,"fork":false,"pushed_at":"2018-12-18T02:21:10.000Z","size":253,"stargazers_count":49,"open_issues_count":3,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-20T13:22:32.401Z","etag":null,"topics":["r","subprocess"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lbartnik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-11-06T00:57:40.000Z","updated_at":"2021-12-09T15:40:50.000Z","dependencies_parsed_at":"2023-03-02T21:15:59.417Z","dependency_job_id":null,"html_url":"https://github.com/lbartnik/subprocess","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lbartnik%2Fsubprocess","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lbartnik%2Fsubprocess/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lbartnik%2Fsubprocess/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lbartnik%2Fsubprocess/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lbartnik","download_url":"https://codeload.github.com/lbartnik/subprocess/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252593046,"owners_count":21773397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["r","subprocess"],"created_at":"2024-08-02T22:01:05.985Z","updated_at":"2025-05-05T23:31:23.700Z","avatar_url":"https://github.com/lbartnik.png","language":"C++","readme":"subprocess\n==========================\n\n| CRAN version    | Travis build status   | AppVeyor | Coverage | Downloads |\n| :-------------: |:---------------------:|:--------:|:--------:|:---------:|\n| [![CRAN version](http://www.r-pkg.org/badges/version/subprocess)](https://cran.r-project.org/package=subprocess) | [![Build Status](https://travis-ci.org/lbartnik/subprocess.svg?branch=master)](https://travis-ci.org/lbartnik/subprocess) | [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/lbartnik/subprocess?branch=master\u0026svg=true)](https://ci.appveyor.com/project/lbartnik/subprocess) | [![codecov](https://codecov.io/gh/lbartnik/subprocess/branch/master/graph/badge.svg)](https://codecov.io/gh/lbartnik/subprocess)| [![cranlogs](https://cranlogs.r-pkg.org/badges/grand-total/subprocess)](https://cranlogs.r-pkg.org/) |\n\n\n\nRun and interact with a child process in R! `subprocess` brings a new\nR API to create, control the life cycle and shutdown a child process\nin **Linux**, **Windows** and **Mac OS**. Check this out.\n\n\n## Remote shell example\n\nHere's an example of running a `ssh` client child process. It connects\nto a ssh server using public key (thus, no password). Then we list files\nin the remote account and finally gracefully shutdown the child process.\n\nLoad the `subprocess` package and start a new child process:\n\n```r\nlibrary(subprocess)\n\nssh_path \u003c- '/usr/bin/ssh'\nhandle \u003c- spawn_process(ssh_path, c('-T', 'test@example'))\n```\n\nHere is the description of the child process:\n\n```r\nprint(handle)\n#\u003e Process Handle\n#\u003e command   : /usr/bin/ssh -T test@example\n#\u003e system id : 17659\n#\u003e state     : running\n```\n\nAnd here is what the child process has sent so far to its output streams:\n\n```r\nprocess_read(handle, PIPE_STDOUT, timeout = TIMEOUT_INFINITE)\n#\u003e [1] \"Welcome to Ubuntu 16.10 (GNU/Linux 4.8.0-27-generic x86_64)\"\n#\u003e [2] \"\"                                                           \n#\u003e [3] \" * Documentation:  https://help.ubuntu.com\"                 \n#\u003e [4] \" * Management:     https://landscape.canonical.com\"         \n#\u003e [5] \" * Support:        https://ubuntu.com/advantage\"            \n#\u003e [6] \"\"                                                           \n#\u003e [7] \"0 packages can be updated.\"                                 \n#\u003e [8] \"0 updates are security updates.\"                            \n#\u003e [9] \"\"\nprocess_read(handle, PIPE_STDERR)\n#\u003e character(0)\n```\n\nNothing in the standard error output. Good! Now we ask the remote shell\nto list files.\n\n```r\nprocess_write(handle, 'ls\\n')\n#\u003e [1] 3\nprocess_read(handle, PIPE_STDOUT, timeout = TIMEOUT_INFINITE)\n#\u003e [1] \"Desktop\"          \"Download\"         \"examples.desktop\"\n#\u003e [4] \"Music\"            \"Public\"           \"Video\"\nprocess_read(handle, PIPE_STDERR)\n#\u003e character(0)\n```\n\nThe first number in the output is the value returned by `process_write()`\nwhich is the number of characters written to standard input of the\nchild process. The final `character(0)` is the output read from the\nstandard error stream.\n\n\nWe are now ready to close the connection by exiting the remote shell:\n\n```r\nprocess_write(handle, 'exit\\n')\n#\u003e [1] 5\nprocess_read(handle, PIPE_STDOUT, timeout = TIMEOUT_INFINITE)\n#\u003e character(0)\nprocess_read(handle, PIPE_STDERR)\n#\u003e character(0)\n```\n\nThe last thing is making sure that the child process is no longer alive:\n\n```r\nprocess_wait(handle, TIMEOUT_INFINITE)\n#\u003e [1] 0\nprocess_status(handle)\n#\u003e [1] \"exited\"\n```\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flbartnik%2Fsubprocess","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flbartnik%2Fsubprocess","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flbartnik%2Fsubprocess/lists"}