Giter Site home page Giter Site logo

effect-deprecated / process Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 0.0 2.52 MB

A simple library for interacting with external processes and command-line programs via Effect-TS (port of zio-process)

License: MIT License

JavaScript 4.68% Shell 0.66% TypeScript 94.66%

process's Introduction

process's People

Contributors

imax153 avatar mikearnaldi avatar sledorze avatar

Stargazers

Max Lay avatar Luke Schoen avatar sam bacha avatar aab avatar Pete Murphy avatar Daniel Pous Montardit avatar Jean-Baptiste Musso avatar Giovanni Ravalico avatar Mocchapine avatar Johannes Schickling avatar

Watchers

 avatar

process's Issues

Redirect stderr to stdout when Command.redirectErrorStream is true

Is your feature request related to a problem? Please describe.

The redirectErrorStream property on a StandardCommand should cause the stderr stream to be redirected to stdout. At the moment, this is not implemented.

Describe the solution you'd like

If we have a shell script called both-streams.sh such as this:

#!/bin/bash

function echoerr {
  echo "$@" 1>&2
}

echo "stdout1"
echoerr "stderr1"

echo "stdout2"
echoerr "stderr2"

then the redirectErrorStream combinator should cause the stderr stream to be redirected to stdout.

  it("should merge stderr into stdout when redirectErrorStream is true", () =>
    T.gen(function* (_) {
      const command = pipe(
        Command.command("./both-streams-test.sh"),
        Command.workingDirectory("packages/process/test/bash"),
        Command.redirectErrorStream(true)
      )
  
      const { stderr, stdout } = yield* _(
        pipe(
          T.do,
          T.bind("process", () => Command.run(command)),
          T.bind("stdout", ({ process }) =>
            ProcessStream.string(Process.stdout(process))
          ),
          T.bind("stderr", ({ process }) =>
            ProcessStream.string(Process.stderr(process))
          )
        )
      )
  
      expect(stderr).toBe("")
      expect(stdout).toBe("stdout1\nstderr1\nstdout2\nstderr\n")
    }))

Describe alternatives you've considered

None

Additional context

Based on this discussion on StackOverflow, it doesn't seem possible to ensure correct ordering of the stdout and stderr output streams.

Also for context:

  • Issue related to this in libuv
  • Issue related to this in node (archive)

Allow for capturing stdout and stderr separately

Is your feature request related to a problem? Please describe.

At the moment, if one would like to capture the output of stdout and stderr separately, it must be done in parallel. For example:

This will properly capture stdout and stderr into a Tuple.

pipe(
  Command.command("ls"),
  Command.run,
  T.chain((process) =>
    T.zipPar_(
      ProcessStream.string(Process.stdout(process)),
      ProcessStream.string(Process.stderr(process))
    )
  )
)

but this will capture only stdout

pipe(
  T.do,
  T.bind("process", () => Command.command("ls")),
  T.bind("stdout", ({ process }) => ProcessStream.string(Process.stdout(process))),
  T.bind("stderr", ({ process }) => ProcessStream.string(Process.stderr(process)))
)

Describe the solution you'd like

To be able to capture stdout and stderr separately even when not running in parallel (as is done in the original implementation).

Describe alternatives you've considered

None

Additional context

I believe the root cause of the issue is how the NodeJS ReadableStream is actually drained here. I am open to suggestions on alternative approaches. For reference, here is the original implementation.

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.