[ch20 John Goerzen **20071010062022] { adddir ./examples/ch20 hunk ./en/ch20-systems.xml 26 + + + Running External Programs + + It is possible to invoke external commands from Haskell. To do that, + we suggest using rawSystem from the + System.Cmd module. This will invoke a specified + program, with the specified arguments, and return the exit code from + that program. You can play with it in &ghci;: + + &rawSystem.ghci:s1; + + Here, we run the equivolent of the shell command ls -l /usr. + rawSystem does not parse arguments from a string or + expand wildcards.There is also a function + system that takes only a single string and + passes it through the shell to parse. We recommend using + rawSystem instead, because the shell attaches + special meaning to certain characters, which could lead to security + issues or unexpected behavior. + Instead, it expects every argument to be contained + in a list. If you don't want to pass any arguments, you can simply + pass an empty list like this: + + &rawSystem.ghci:s2; + addfile ./examples/ch20/rawSystem.ghci hunk ./examples/ch20/rawSystem.ghci 1 +--# s1 +:m System.Cmd +rawSystem "ls" ["-l", "/usr"] +--# s2 +rawSystem "ls" [] }