GithubHelp home page GithubHelp logo

joshooaj / bgprocess Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 2.0 1.29 MB

Start a process and asynchronously access the STDIO streams

Home Page: https://www.joshooaj.com/BGProcess

License: MIT License

Dockerfile 6.54% PowerShell 93.46%
powershell process stdio

bgprocess's People

Contributors

joshooaj avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

donovoi

bgprocess's Issues

Consider leveraging OutputDataReceived event

The method of monitoring StandardOutput and StandardError in this module is to read the streams from a separate runspace where, if the read operation blocks, it doesn't have to impact the user's shell.

Another option for reading from these streams is to use 'Register-ObjectEvent' to subscribe to the OutputDataReceived and ErrorDataReceived events.

This could simplify the module a bit, but it looks like the event only fires when a newline is encountered. This means that when an application prompts for input, typically you wouldn't receive the prompt until you blindly write to StandardInput and cause the application to write a newline.

The events also exclusively send string data, so if I want to add binary support to the module the event handlers wouldn't be an option.

Because of these two issues, I'm leaning towards avoiding the event handlers entirely. The only true advantage of using them was being able to interleave stdout and stderr messages accurately, but this can be done in the current implementation with some smarter processing anyway.

Interleave stdout and stderr

Currently, all of the StandardError content is returned, followed by all of the StandardOutput content, each as individual strings.

This means the output order is not being preserved, and we can't tell how much time passed between two lines of output.

Instead of returning strings, Read-BGProces could return a rich object similar to BGProcessRecord...

enum StdIOStream {
    StandardOutput
    StandardError
    StandardInput
}

class BGProcessRecord {
    [int]         $PID
    [datetime]    $Timestamp
    [StdIOStream] $Stream
    [string]      $Content
}

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.