Unix.create_process
actually calls fork
and the does an execvpe
, which itself calls the execv
primitive (in the OCaml C implementation of the Unix
module).
That function then calls cstringvect
(a helper function in the C side of the module implementation), which translates the arg parameters into an array of C string, with last entry set to NULL
. However, execve
and the like expect by convention (see the execve(2)
linux man page) the first entry of that array to be the name of the program:
argv is an array of argument strings passed to the new program. By
convention, the first of these strings should contain the filename
associated with the file being executed.
That first entry (or rather, the copy it receives) can actually be changed by the program receiving these args, and is displayed by ls
, top
, etc.
"ls"
needs to be in the array. The documentation doesn't make that statement though. I don't have any crashing when I execute this statement as is -- an, "A NULL argv[0] was passed through an exec system call.", but that's it.let inchan,outchan = Unix.open_process "ls";;
is probably what you want in this case, of course if you're simplifying the situation then hopefully someone else can help.let _ = Unix.create_process "./test.native" [||] Unix.stdin Unix.stdout Unix.stderr
, it workedUnix.create_process "ls" [|""|] Unix.stdin Unix.stdout Unix.stderr;;
will work. Could this be how[||]
is represented when making syscalls?[||]
worked for a simpletest.native
inside whichlet _ = print_endline "hello"
?