GithubHelp home page GithubHelp logo

connectedbits / subexec Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pressly/subexec

0.0 4.0 0.0 24 KB

Subexec spawns an subprocess with an optional timeout

License: MIT License

Ruby 99.35% Shell 0.65%

subexec's Introduction

Subexec

by Peter Kieltyka http://github/nulayer/subexec

Description

Subexec is a simple library that spawns an external command with an optional timeout parameter. It relies on Ruby 1.9's Process.spawn method. Also, it works with synchronous and asynchronous code.

Useful for libraries that are Ruby wrappers for CLI's. For example, resizing images with ImageMagick's mogrify command sometimes stalls and never returns control back to the original process. Enter Subexec.

Tested with MRI 1.9.3, 1.9.2, 1.8.7

Note: Process.spawn seems to be broken with JRuby 1.7.0.dev (as of April 20th, 2012), and so it uses Process.exec instead.

Usage

sub = Subexec.run "echo 'hello' && sleep 3", :timeout => 5
puts sub.output     # returns: hello
puts sub.exitstatus # returns: 0

sub = Subexec.run "echo 'hello' && sleep 3", :timeout => 1
puts sub.output     # returns: 
puts sub.exitstatus # returns:`

Limitations

Only Ruby 1.9 can spawn non-blocking subprocesses, via Process.spawn. So Ruby 1.8 support is sheerly for backwards compatibility.

Windows Support

Limited Windows support is available. We are more than happy to accept patches. However, our tests are run on Unix-like operating systems. Primarily, the intended effect should be that Subexec works on Windows, though it may not give many advantages.

subexec's People

Contributors

davemitchell avatar hamptonmakes avatar johnthethird avatar ralph avatar

Watchers

 avatar  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.