[GHC] #8838: Allow running bash shell commands

#8838: Allow running bash shell commands --------------------------+------------------------------------------------ Reporter: | Owner: jstolarek | Status: new Type: | Milestone: 7.10.1 feature request | Version: 7.8.1-rc2 Priority: normal | Operating System: Linux Component: | Type of failure: Incorrect result at runtime libraries/process | Test Case: Keywords: | Blocking: Architecture: | Unknown/Multiple | Difficulty: | Unknown | Blocked By: | Related Tickets: #8802 | --------------------------+------------------------------------------------ Current implementation of `process` library has limited usability. `CreateProcess` record stores `CmdSpec` field, which is either a `RawCommand` or `ShellCommand`. The problem is that: * `RawCommand` command quotes and escapes the command parameters * `ShellCommand` does no escaping but it runs command in `sh` shell Corollary: there is no way to run `bash` command with unescaped parameters. As a result there is no way to run this command (and many others): {{{ diff <(echo $ENV_FOO) <(echo $ENV_BAR) }}} Running it as a `RawCommand` (using `proc` function) fails because command line parameters are escaped and become incorrect. Running it as `ShellCommand` (using `shell` function) fails because this is not valid `sh` syntax. I propose to create function that allows user to run `bash` commands without escaping the parameters (or even better, run any shell the user wants). In other words this program: {{{ import System.Exit import System.Process main :: IO () main = do (_, _, _, pid) <- createProcess (SOME_NEW_FUNCTION "diff" ["<(echo $FOO)", "<(echo $BAR)"] ) { env = Just [("FOO","Foo"),("BAR","Bar")] } ecode <- waitForProcess pid case ecode of ExitSuccess -> putStrLn "All’s right with the world!" ExitFailure _ -> putStrLn ":-(" }}} should produce: {{{ 1c1 < Foo ---
Bar }}}
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8838 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8838: Allow running bash shell commands ------------------------------------------------+-------------------------- Reporter: jstolarek | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.10.1 Component: libraries/process | Version: Resolution: | 7.8.1-rc2 Operating System: Linux | Keywords: Type of failure: Incorrect result at runtime | Architecture: Test Case: | Unknown/Multiple Blocking: | Difficulty: | Unknown | Blocked By: | Related Tickets: #8802 ------------------------------------------------+-------------------------- Comment (by nomeata): Use {{{ import System.Exit import System.Process main :: IO () main = do (_, _, _, pid) <- createProcess (proc "bash" ["-c", "diff <(echo $FOO) <(echo $BAR)"] ) { env = Just [("FOO","Foo"),("BAR","Bar")] } ecode <- waitForProcess pid case ecode of ExitSuccess -> putStrLn "All’s right with the world!" ExitFailure _ -> putStrLn ":-(" }}} I don’t think `System.Process` needs any special support for `bash` features, just like there is no special way to invoke `perl -e` or `sed` or `ghc -e`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8838#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8838: Allow running bash shell commands ------------------------------------------------+-------------------------- Reporter: jstolarek | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.10.1 Component: libraries/process | Version: Resolution: | 7.8.1-rc2 Operating System: Linux | Keywords: Type of failure: Incorrect result at runtime | Architecture: Test Case: | Unknown/Multiple Blocking: | Difficulty: | Unknown | Blocked By: | Related Tickets: #8802 ------------------------------------------------+-------------------------- Comment (by jstolarek):
I don’t think System.Process needs any special support for bash features Well, there is a built in support for running `sh`...
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8838#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8838: Allow running bash shell commands ------------------------------------------------+-------------------------- Reporter: jstolarek | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.10.1 Component: libraries/process | Version: Resolution: | 7.8.1-rc2 Operating System: Linux | Keywords: Type of failure: Incorrect result at runtime | Architecture: Test Case: | Unknown/Multiple Blocking: | Difficulty: | Unknown | Blocked By: | Related Tickets: #8802 ------------------------------------------------+-------------------------- Comment (by nomeata):
Well, there is a built in support for running sh...
Correct, because a POSIX shell is, by specification, part of a unix system; random and exotic bash features are not. In any case, I’d advise against using shell commands in serious projects, especially with untrusted data, the risks are just too great. Is `proc "bash" ["-c", "..."]` not sufficient for your use cases? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8838#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8838: Allow running bash shell commands ------------------------------------------------+-------------------------- Reporter: jstolarek | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.10.1 Component: libraries/process | Version: Resolution: | 7.8.1-rc2 Operating System: Linux | Keywords: Type of failure: Incorrect result at runtime | Architecture: Test Case: | Unknown/Multiple Blocking: | Difficulty: | Unknown | Blocked By: | Related Tickets: #8802 ------------------------------------------------+-------------------------- Comment (by jstolarek):
Is proc "bash" ["-c", "..."] not sufficient for your use cases? Yes, it is. I wonder why this works? I mean parameters are escaped.
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8838#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8838: Allow running bash shell commands ------------------------------------------------+-------------------------- Reporter: jstolarek | Owner: Type: feature request | Status: closed Priority: normal | Milestone: 7.10.1 Component: libraries/process | Version: Resolution: invalid | 7.8.1-rc2 Operating System: Linux | Keywords: Type of failure: Incorrect result at runtime | Architecture: Test Case: | Unknown/Multiple Blocking: | Difficulty: | Unknown | Blocked By: | Related Tickets: #8802 ------------------------------------------------+-------------------------- Changes (by jstolarek): * status: new => closed * resolution: => invalid -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8838#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8838: Allow running bash shell commands ------------------------------------------------+-------------------------- Reporter: jstolarek | Owner: Type: feature request | Status: closed Priority: normal | Milestone: 7.10.1 Component: libraries/process | Version: Resolution: invalid | 7.8.1-rc2 Operating System: Linux | Keywords: Type of failure: Incorrect result at runtime | Architecture: Test Case: | Unknown/Multiple Blocking: | Difficulty: | Unknown | Blocked By: | Related Tickets: #8802 ------------------------------------------------+-------------------------- Comment (by nomeata): Replying to [comment:4 jstolarek]:
Is proc "bash" ["-c", "..."] not sufficient for your use cases? Yes, it is. I wonder why this works? I mean parameters are escaped.
No, they are not – `translate` is not used here! (as mentioned in ticket:8802#comment:6). But that explains the confusion :-) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8838#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8838: Allow running bash shell commands ------------------------------------------------+-------------------------- Reporter: jstolarek | Owner: Type: feature request | Status: closed Priority: normal | Milestone: 7.10.1 Component: libraries/process | Version: Resolution: invalid | 7.8.1-rc2 Operating System: Linux | Keywords: Type of failure: Incorrect result at runtime | Architecture: Test Case: | Unknown/Multiple Blocking: | Difficulty: | Unknown | Blocked By: | Related Tickets: #8802 ------------------------------------------------+-------------------------- Comment (by jstolarek): Oh, I completely missed your [[ticket:8802#comment:8]] comment! My bad. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8838#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC