How to use "ocaml -stdin"?

Hello everyone,

I’m trying to use the “ocaml -stdin” command. The documentation says: “Read the standard input as a script file rather than starting an interactive session.” But when I write “1+1;;” or “print_int 1;;” or “1+1; exit 0;;” possibly followed by Ctrl+C or Ctrl+D, nothing happens.
What am I doing wrong?

Thanks !

In -stdin mode, the interpreter does not print the type and value of expressions. Also I think it expects the whole file, so all your lines only start being evaluated when you hit CTRL-D. If you do CTRL-C, it just terminates the process without evaluating anything.

print_int 1;; followed by CTRL-D should definitely print 1, but since there is no \n maybe you did not see it or it mangled by your shell prompt ?
Can you try
print_endline "Hello, world\n";;
followed by ctrl-D ?

You’re right:
print_endline “Hello, world\n”;;
followed by ctrl-D
works

Thanks !