Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Implement a way to construct pipes #12

Open
chshersh opened this issue Jul 28, 2019 · 8 comments
Open

[RFC] Implement a way to construct pipes #12

chshersh opened this issue Jul 28, 2019 · 8 comments
Labels
enhancement New feature or request

Comments

@chshersh
Copy link
Contributor

When I need to call pipes I often end with the code like this:

callCommand $ "git diff " <> commit <> " --color=always | diff-highlight | less -rFX"

I can use $| operator but it's not efficient. So maybe having some additional function would be useful and I can rewrite it like this:

pipes $ "git" [commit, "--color=always"] <> "diff-highlight" [] <> "less" ["-rfX"]
@chshersh chshersh added the enhancement New feature or request label Jul 28, 2019
@chshersh chshersh changed the title Implement a way to construct pipes [RFC] Implement a way to construct pipes Sep 28, 2019
@v217
Copy link

v217 commented Nov 14, 2019

Is it possible to call subprocesses directly, without executing the shell sh -c ? Thanks!

@chshersh
Copy link
Contributor Author

@v217 Could you elaborate more on your question? I'm not sure I understand it completely...

@v217
Copy link

v217 commented Nov 14, 2019

@chshersh Sure, if I now write

"sleep" ["1000"]

ghci calls sh -c 'sleep 1000' instead of execve sleep 1000 without calling the shell.
So in your terminal running ps -e you see:

ghci
     sh
         sleep

@chshersh
Copy link
Contributor Author

@v217 Thanks for the clarification! I see what do you mean now. This happens because we're using callCommand function from the process library here:

  • shellmet/src/Shellmet.hs

    Lines 39 to 41 in d701862

    let cmdStr = showCommandForUser cmd (map T.unpack args)
    putStrLn $ "" ++ cmdStr
    callCommand cmdStr

This command constructs a process using ShellComand constructor of the CmdSpec data type:

According to the documentation (if my understanding is correct), it should be possible to replace callCommand with callProcess to create subprocesses directly. However, I'm afraid to perform this change because I'm not sure how it will behave on various systems (Linux, Windows, macOS). We're currently using shellmet in multiple projects, and they were tested on Windows by volunteers, and we know that the tools work. But I don't have time and capability to test these changes on Windows my myself (and not even sure how to do this), so I'm a bit reluctant to perform this refactoring that can potentially break some production code.

Are there any drawbacks regarding using a command from shell?

@v217
Copy link

v217 commented Nov 14, 2019

@chshersh No, apart from shell scripts not being portable, and any shell bug, security flaw might also affect the haskell script. Anyway Thanks for the callProcess link! I am on ubuntu and I will modify your script to use callProcess. I think, if you want to implement Pipes, you have to use callProcess? Currently I am interested in simple scripting solutions for haskell. I am also experimenting with Shh, the most lightweight scripting solution for haskell, I tried so far.

@chshersh
Copy link
Contributor Author

Ah, I've also been looking at shh and I like the library. Looks like it handles pipes quite nice. Unfortunately, shh works only on Unix system, and for our purposes, we want to be able to run shell commands on Windows as well. That's why shellmet is a simple solution that works for simple cases.

@v217
Copy link

v217 commented Nov 14, 2019

I agree, leaving it that simple is certainly an advantage!

@andreasabel
Copy link

Ah, I've also been looking at shh and I like the library. Looks like it handles pipes quite nice. Unfortunately, shh works only on Unix system

Maybe use https://github.com/gregwebs/Shelly.hs which is (ideally) system-agnostic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants