Run program with arguments

Help
audle
2012-11-29
2012-12-06
  • audle

    audle - 2012-11-29

    Hello,

    my main function looks like this:

    main = do
      [a, b, c, d] <- getArgs
      ...
    

    On the terminal I can compile and run it with ./main fst snd third fourth
    How can I tell Eclipse to run the programm with arguments of my choice?
    I tried adding the arguments "fst snd third fourth" in the argument-field which can be found at >Right click on properties of project> Run as > Run configurations > Haskell application > <Project name>
    In contrast to running the programming without the arguments entered in this field, there is no pattern-machting-error anymore and eclipse says in the right corner: Running executable /usr/bin/ghc, but nothing more happens, I can't see anything on the Console

     
  • JP Moresmau

    JP Moresmau - 2012-11-29

    It works fine, don't know what you're doing., can you post screenshots or detail more what you're seeing
    I have a project with a Main.hs in the executable section:
    main :: IO()
    main = do
              <- getArgs
             putStrLn a

    Put arg0 arg1 arg2 arg3 in the arguments field of the Haskell Application run configurations, I get arg0 back. If I put nothing I get a pattern failure exception

     
  • JP Moresmau

    JP Moresmau - 2012-11-29

    BTW  Running executable /usr/bin/ghc means you're running ghci, I'd say, and not your executable. You need to run a run configuration that's of type HAskell application, not Haskell interactive session. Check all your consoles…

     
  • audle

    audle - 2012-11-29

    Oh yes, I meant Running executable /…<project>.
    The program ends when an EOF is evoked, and I discovered that the program runs, but everthing gets printed to the screen only at the end at once, when EOF is evoked (by pressing CTRL+D under linux).
    When I run it via the console, everything gets printed to the screen at the 'right' time, not all at once at the end.

     
  • audle

    audle - 2012-11-29

    Sorry, I mixed it up - forget about EOF.
    I have some putStrLn's, then I spark a thread in which I compute some data. In the main thread I wait for the user to type "x". When x is typed the program ends and all the Strings I wanted to print to the terminal before are printed.

     
  • audle

    audle - 2012-12-01

    Consider this program:

    main :: IO() 
    main = do
      putStrLn "test"
      getLine >>= putStrLn
    

    If it is run in the "interactive session" mode (ghci) I get the desired output: "test" is printed, and then it is waited for a line entered, this is printed to the screen then.

    But if you run it as "Haskell application", that means you run the compiled file, "test" isn't printed to the screen until the user entered a line.

     

Log in to post a comment.