How to Launch an Editor from Escript?

Can you at least be sure they have screen (comes by default on about everything but windows)? ^.^;

I can make that assumption, yes screen will be installed. The tool is used on MacOSX and Linux

I’d say call in to that then to have it create a new window in it to load the editor of whatever you need. ^.^;

I must be missing something. Do I need to redirect i/o somehow?

case System.cmd("screen", ["vim"]) do
  {resp, _} ->

    Logger.debug(inspect(resp))
    Logger.debug("Screen Called")
end

13:25:20.797 [debug] "Must be connected to a terminal.\r\n"
13:25:20.797 [debug] Screen Called

The BEAM VM detaches in general, I.E. it doesn’t have an stdin/stdout (hence your issue). If you run a BEAM VM program in a terminal it keeps a ‘loader’ loaded to pass messages to/from to send things to/from your terminal, but it itself still does not really have an stdin/stdout ‘per-say’, hence why you need to tell screen to load a new window with the editor. The command you are doing is trying to load an entirely new screen instance as a child of the BEAM VM process, where instead you should tell it to open it external to it (or if you are on linux, you could just xdg-open <file> to let it open in whatever they have default set to that file type).

I hate to say this
 but you lost me. :man_facepalming:

I can create a temp file for vim to open for editing however am not groking how to have Elixir/Escript execute screen successfully and wait for screen to close.

Well you could wait for screen to close but when you initiate a command to screen to open another screen then the original command returns immediately, I.E. you will not be able to wait for when it closes.

Let me ask you this:
What would you do to open whatever editor and do whatever you want to do, when you have no stdin/stdout? The answer to this will frame the rest of what you do. :slight_smile:

(I would probably just xdg-open whatever I want to edit and wait for user feedback from the main process for when to continue)

1 Like

yeah you are right
 that will work. Thanks!

1 Like

For anyone who also ends up in this thread years later via Google, I ended up implementing the Port solution given here, which worked perfectly.

1 Like