GithubHelp home page GithubHelp logo

childprocess-server's Introduction

childprocess-server

Gem Version Build Status Code Climate

Manage and interact with processes, remotely (via dRuby).

Installation

gem install childprocess-server

Usage

Standalone

require 'childprocess-server'
server = ChildProcess::Server.new

# Run a process
pid = server.launch('sleep', '1000')
server.alive?(pid) # => true
server.stop(pid)
server.alive?(pid) # => false

# Run 'echo', get output
pid = server.launch('echo', 'hello')
server.read_output(pid) # => "hello\n"
server.alive?(pid) # => false

# Run 'cat', write stdin interactively
pid = server.launch('cat')
server.write_input(pid, "foo\n")
server.read_output(pid) # => "foo\n"
server.write_input(pid, "bar\n")
server.read_output(pid) # => "foo\nbar\n"
server.stop(pid)

# List all process ids managed
# Note: exited processes are also listed.
server.list_pids # => [ ... ]

# Clean up
server.clean_up
server.list_pids # => []

Client / Server

DRB_URI = 'drbunix://tmp/a.socket'

# Server side
ChildProcess::Server.new.start_service(DRB_URI) # will block by default

# Client side
server = ChildProcess::Server.connect(DRB_URI)
pid = server.launch('sort', '-n')
server.write_input(pid, "20\n10\n2\n1\n")
server.read_output(pid) # => "1\n2\n10\n20\n"

Notes

  • This library is thread-safe.
  • This library does not have authentic feature. Set file system permissions or firewall for security.
  • After stop, output can still be read using read_output, because outputs are stored in temporary files. Use clean_up to delete them immediately. Otherwise they are deleted when server exits.
  • If read_output or write_input encounters errors, they just return nil instead of raising an error.

childprocess-server's People

Contributors

dependabot[bot] avatar quark-zju avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.