Hi,
I’m trying to execute ls
on a distant machine using Lwt_process
, Lwt_io
and Lwt_stream
.
The code to read the directory is the following:
let readdir_aux ~remote dir =
let cmd = Format.sprintf "ls -1 %s" dir in
let ssh_cmd = create_ssh_cmd remote cmd in
let lines =
Lwt_process.pread_lines
~timeout:10.0
~stdin:`Dev_null
~stderr:`Dev_null
ssh_cmd
in
Lwt_main.run @@
(Lwt_stream.to_list lines
>>= fun lines ->
List.filter (fun line -> line <> "") lines
|> Array.of_list |> Lwt.return)
When I run the code with no try-with
, I have absolutely no issue:
let () =
Sys.readdir_aux ~remote "/tmp/tryme/"
|> Array.iter (fun x -> Format.printf "-%s\n" x)
But, if I had a try catch to surround the call, it just stops:
let () =
try
Sys.readdir_aux ~remote "/tmp/tryme/"
|> Array.iter (fun x -> Format.printf "-%s\n" x)
with _ -> Format.printf "[OK] Exception readdir@."
Does someone already have this issue ? I can’t see what I missed…