diff options
| author | hallgren <hallgren@chalmers.se> | 2013-11-19 15:18:58 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2013-11-19 15:18:58 +0000 |
| commit | ddac5f9e5aa935f4c154253831a36e49a48cdc8d (patch) | |
| tree | a58846318676f398077d4779fd15d3a589eed2ec /src/compiler/GF/Command/Commands.hs | |
| parent | 5b83da558327b53e857ba88f91cba76821ecf763 (diff) | |
GF shell: improved system_pipe (aka "?") command
1. No temporary files are created.
2. The output of a system command is read lazily, making it feasible to
process large or even infinite output, e.g. the following works as
expected:
? "yes" | ? "head -5" | ps -lextext
Diffstat (limited to 'src/compiler/GF/Command/Commands.hs')
| -rw-r--r-- | src/compiler/GF/Command/Commands.hs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/compiler/GF/Command/Commands.hs b/src/compiler/GF/Command/Commands.hs index 0d1b9695a..44d514a2f 100644 --- a/src/compiler/GF/Command/Commands.hs +++ b/src/compiler/GF/Command/Commands.hs @@ -46,6 +46,7 @@ import Data.List(intersperse,nub) import Data.Maybe import qualified Data.Map as Map --import System.Cmd(system) -- use GF.Infra.UseIO.restricedSystem instead! +import GF.System.Process import Text.PrettyPrint import Data.List (sort) --import Debug.Trace @@ -866,12 +867,15 @@ allCommands = Map.fromList [ synopsis = "send argument to a system command", syntax = "sp -command=\"SYSTEMCOMMAND\", alt. ? SYSTEMCOMMAND", exec = \_ opts arg -> do + let syst = optComm opts -- ++ " " ++ tmpi + {- let tmpi = "_tmpi" --- let tmpo = "_tmpo" restricted $ writeFile tmpi $ toString arg - let syst = optComm opts -- ++ " " ++ tmpi restrictedSystem $ syst ++ " <" ++ tmpi ++ " >" ++ tmpo fmap fromString $ restricted $ readFile tmpo, + -} + fmap fromString . restricted . readShellProcess syst $ toString arg, flags = [ ("command","the system command applied to the argument") ], |
