Is there any way to open a terminal device file in erlang ?
I am on Solaris and I am trying the following::
Erlang (BEAM) emulator version 5.6 [source] [64-bit] [async-threads:0] [kernel-poll:false] /xlcabpuser1/xlc/abp/arunmu/Dolphin/ebin Eshell V5.6 (abort with ^G) 1> file:open("/dev/pts/2",[write]). {error,eisdir} 2> file:open("/dev/null",[write]). {ok,} 3>
As can be seen above the erlang file driver has no problem in opening a null fle but does not open a terminal device file!!
Unable to come to a conclusion as the file driver is able to open a null file.
Is there any other way to open terminal device files ?
Thanks
Update: I was able to work around the limitation described below using a port. For example, here is a sample program that prints "hello world" to
/dev/stdout
:This is a bit inconvenient because a port doesn't act like a regular file, but at least it's one way to get the job done.
In
efile_openfile()
(inerts/emulator/drivers/unix/unix_efile.c
) there is the following code:This code (confusingly) returns the
EISDIR
error if the file is not a regular file (which is theISREG(statbuf)
check), unless the file specifically is/dev/null
. Thefile(3)
documentation states:so it's actually documented to do that. I'm not sure why that restriction exists, though—perhaps it's got something to do with performance because device drivers might block for more time than an ordinary file generally will.