X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=System%2FCmd.hs;h=6fe8fa142c99e662573b77916c5dbe43d2d9671d;hb=b6ef4d7236a944f4ffed7aaa0fa8fcfe18cb77b9;hp=0b093da64316baf936989b3691fd381673da0279;hpb=c10f36a0be68775953958540d745bbd44b081a30;p=ghc-base.git diff --git a/System/Cmd.hs b/System/Cmd.hs index 0b093da..6fe8fa1 100644 --- a/System/Cmd.hs +++ b/System/Cmd.hs @@ -100,6 +100,8 @@ foreign import ccall unsafe "rawSystem" -- a single string. Command-line parsing is done by the executable -- itself. rawSystem cmd args = do + -- NOTE: 'cmd' is assumed to contain the application to run _only_, + -- as it'll be quoted surrounded in quotes here. let cmdline = translate cmd ++ concat (map ((' ':) . translate) args) withCString cmdline $ \pcmdline -> do status <- throwErrnoIfMinus1 "rawSystem" (c_rawSystem pcmdline) @@ -108,6 +110,7 @@ rawSystem cmd args = do n -> return (ExitFailure n) translate :: String -> String +translate str@('"':_) = str -- already escaped. translate str = '"' : foldr escape "\"" str where escape '"' str = '\\' : '"' : str escape '\\' str = '\\' : '\\' : str