Loading ...
Sorry, an error occurred while loading the content.

Unix.open_process blocks ocaml under linux

Expand Messages
  • jshaw10
    This question has been asked once before but had no replies: http://tech.groups.yahoo.com/group/ocaml_beginners/message/8722 Why does the following work under
    Message 1 of 4 , Jan 3, 2009
    • 0 Attachment
      This question has been asked once before but had no replies:
      http://tech.groups.yahoo.com/group/ocaml_beginners/message/8722

      Why does the following work under Windows but not Linux (Debian lenny
      in my case). I tried both ocaml, ocamlc, and ocamlopt and they all
      hang at Unix.open_process. I made sure the name of the executable was
      correct of course.

      # #load "unix.cma";;
      # let (wishin,wishout) = Unix.open_process "wish85";;
      val wishin : in_channel = <abstr>
      val wishout : out_channel = <abstr>
      # output_string wishout "button .b -text Hello\n";;
      - : unit = ()
      # output_string wishout "pack .b\n";;
      - : unit = ()
      # flush wishout;;
      - : unit = ()

      Thanks for any help,
      Jeff
    • Adrien
      This is just a quick check. Have you tried giving the full path to open_process ? Or specify ./wish85 instead of just wish85 ? IIRC the current directory
      Message 2 of 4 , Jan 3, 2009
      • 0 Attachment
        This is just a quick check. Have you tried giving the full path to
        open_process ? Or specify "./wish85" instead of just "wish85" ?
        IIRC the current directory is part of a program's path on windows (or
        is it its directory that is part, or both ?).


        ---

        Adrien Nader

        2009/1/3, jshaw10 <jshaw10@...>:
        > This question has been asked once before but had no replies:
        > http://tech.groups.yahoo.com/group/ocaml_beginners/message/8722
        >
        > Why does the following work under Windows but not Linux (Debian lenny
        > in my case). I tried both ocaml, ocamlc, and ocamlopt and they all
        > hang at Unix.open_process. I made sure the name of the executable was
        > correct of course.
        >
        > # #load "unix.cma";;
        > # let (wishin,wishout) = Unix.open_process "wish85";;
        > val wishin : in_channel = <abstr>
        > val wishout : out_channel = <abstr>
        > # output_string wishout "button .b -text Hello\n";;
        > - : unit = ()
        > # output_string wishout "pack .b\n";;
        > - : unit = ()
        > # flush wishout;;
        > - : unit = ()
        >
        > Thanks for any help,
        > Jeff
        >
        >
        > ------------------------------------
        >
        > Archives up to December 31, 2007 are also downloadable at
        > http://www.connettivo.net/cntprojects/ocaml_beginners/
        > The archives of the very official ocaml list (the seniors' one) can be found
        > at http://caml.inria.fr
        > Attachments are banned and you're asked to be polite, avoid flames
        > etc.Yahoo! Groups Links
        >
        >
        >
        >
      • jshaw10
        That worked, thanks! ... can be found
        Message 3 of 4 , Jan 3, 2009
        • 0 Attachment
          That worked, thanks!

          --- In ocaml_beginners@yahoogroups.com, Adrien <camaradetux@...> wrote:
          >
          > This is just a quick check. Have you tried giving the full path to
          > open_process ? Or specify "./wish85" instead of just "wish85" ?
          > IIRC the current directory is part of a program's path on windows (or
          > is it its directory that is part, or both ?).
          >
          >
          > ---
          >
          > Adrien Nader
          >
          > 2009/1/3, jshaw10 <jshaw10@...>:
          > > This question has been asked once before but had no replies:
          > > http://tech.groups.yahoo.com/group/ocaml_beginners/message/8722
          > >
          > > Why does the following work under Windows but not Linux (Debian lenny
          > > in my case). I tried both ocaml, ocamlc, and ocamlopt and they all
          > > hang at Unix.open_process. I made sure the name of the executable was
          > > correct of course.
          > >
          > > # #load "unix.cma";;
          > > # let (wishin,wishout) = Unix.open_process "wish85";;
          > > val wishin : in_channel = <abstr>
          > > val wishout : out_channel = <abstr>
          > > # output_string wishout "button .b -text Hello\n";;
          > > - : unit = ()
          > > # output_string wishout "pack .b\n";;
          > > - : unit = ()
          > > # flush wishout;;
          > > - : unit = ()
          > >
          > > Thanks for any help,
          > > Jeff
          > >
          > >
          > > ------------------------------------
          > >
          > > Archives up to December 31, 2007 are also downloadable at
          > > http://www.connettivo.net/cntprojects/ocaml_beginners/
          > > The archives of the very official ocaml list (the seniors' one)
          can be found
          > > at http://caml.inria.fr
          > > Attachments are banned and you're asked to be polite, avoid flames
          > > etc.Yahoo! Groups Links
          > >
          > >
          > >
          > >
          >
        • Richard Jones
          ... I think CamaradeTux nailed your problem with the $PATH. However I d like to add that opening two channels like this isn t necessarily safe. You can easily
          Message 4 of 4 , Jan 3, 2009
          • 0 Attachment
            On Sat, Jan 03, 2009 at 11:09:26AM -0000, jshaw10 wrote:
            > This question has been asked once before but had no replies:
            > http://tech.groups.yahoo.com/group/ocaml_beginners/message/8722
            >
            > Why does the following work under Windows but not Linux (Debian lenny
            > in my case). I tried both ocaml, ocamlc, and ocamlopt and they all
            > hang at Unix.open_process. I made sure the name of the executable was
            > correct of course.
            >
            > # #load "unix.cma";;
            > # let (wishin,wishout) = Unix.open_process "wish85";;
            > val wishin : in_channel = <abstr>
            > val wishout : out_channel = <abstr>
            > # output_string wishout "button .b -text Hello\n";;
            > - : unit = ()
            > # output_string wishout "pack .b\n";;
            > - : unit = ()
            > # flush wishout;;
            > - : unit = ()

            I think CamaradeTux nailed your problem with the $PATH.

            However I'd like to add that opening two channels like this isn't
            necessarily safe. You can easily get into a deadlock situation where
            [amongst other cases] the parent process can be trying to write to the
            child process, which is trying to write to the parent process, and
            neither process can proceed.

            The more general way to solve this is either to send the output
            somewhere else (eg. to a file which you can read back later) or to use
            a program like 'expect'.

            https://secure.wikimedia.org/wikipedia/en/wiki/Expect

            (Or, I guess, use Gtk instead :-)

            Rich.

            --
            Richard Jones
            Red Hat
          Your message has been successfully submitted and would be delivered to recipients shortly.