9

hi I need to read the command line standard out after executing a haskell command, i know there are two modules to execute system commands: System.Cmd and System.Process

can anybody show me a simple example how to run the System.Process functions?

here is a example what i need to do (i know there is System.Directory to do that but i thought this is a good example):

  1. execute a system command like ls -a
  2. now i dont want the user to see the output
  3. the output should only be accessable in my program to validate it

how can i do that?

2
  • 1
    I think you mean read a command's output, not read the command line. The command line means the name of the command being executed and its arguments. Commented May 20, 2011 at 14:44
  • 2
    The edit to the question is confusing. I interpreted the original as asking about reading the new process' standard out rather than in. Commented May 20, 2011 at 18:00

1 Answer 1

20
import System.Process
test = readProcess "ls" ["-a"] ""

Do refer to the documentation for usage details.

Sign up to request clarification or add additional context in comments.

3 Comments

@Tarrasch The "ls" command is of course not platform independent, but readProcess should be. The documentation for System.Process mentions various areas where Windows' behavior deviates from the Unix-based platforms.
It's better to use readProcessWithExitCode.
Documentation link is dead, and this no solution no longer works.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.