I recently started using OCaml on my Windows machine and I have been using cygwin for compilation and execution of my programs. I recently had to create a program which takes user input from stdin using Lexing.from_channel stdin. The Problem I am running into is that I type in the input, but nothing happens. After checking out some things I found that there is no indication the input is being finished so the program is just waiting on more input. I have tried ctrl-D after I type in the input and nothing happens and ctrl-z which just displays Stopped and ends the program. Additionally, when i use these keys cygwin will often crash. Does anyone have an idea on how to indicate end of input for user inputs in OCaml?
1 Answers
My personal recommendation: if you can access Unix or Mac OS X, use them. Using OCaml over Windows is pain unless you get paid for it. Using OCaml in a virtual Unix environment like VMWare is another option.
Currently we have 3 OCaml flavors in Windows: Native MS, Native MinGW and Cygwin. See http://caml.inria.fr/distrib/ocaml-4.01/notes/README.win32 for details.
Any question about OCaml in Windows, you must first state clearly which flavour of OCaml you use. I suspect you use MinGW OCaml over Cygwin. With this combination I have the exactly same troubles you have described.
- Ctrl-D is not considered as closing stdin in MinGW OCaml, since it is Windows console app.
- Ctrl-Z is to close stdin in MinGW OCaml, but it is first fetched by your Cygwin terminal, then it suspends the process
- Once 'Stopped' by Ctrl-Z, normally the OCaml process and the terminal go into strange states and you have to kill them. (I want to walk away from it, rather than tracking what is really happening.)
- If you execute your MinGW OCaml apps over Command Prompt, your stdin works fine.
If you prefer Cygwin and your work does not involve with selling your binary executables, using Cygwin OCaml is the way to go. But still, there are very few people working there. I am afraid that any Cygwin OCaml specific questions may not be answered even in StackOverflow.
Maybe my view is too pesimistic. I hope some OCaml + MingW experts would give some more insights.
your_ocaml_program < fileorother_command | your_ocaml_program)? That should really force OCaml to recognize that input has ended. If even that doesn't work, then I really think the problem is probably with your code (or with how you're compiling it). - ruakh