[erlang-questions] Passing parameters to a port driver

Per Hedeland per@REDACTED
Sat Mar 8 22:02:54 CET 2008

Sebastian Bello <sebastian.bello@REDACTED> wrote:
>There is no argc/argv in a linked in driver as far as I know.

Hm, it was a while ago, but according to your quote I wrote:

>> (An external port program would (at least on *nix) get
>> the Command in the argc/argv arguments to main()...)

I'm sorry, but I'm quite unable to parse that as a claim that a driver
would get argc/argv, so I have no idea why you feel the need to state
that it doesn't. But you're quite correct of course.

> On the 
>driver side you have
>    static ErlDrvData driver_start(ErlDrvPort port, char *buff)

Exactly, and as I recall your question was what was in the "buff", which
I explained.

>and buff just points to the driver name;

It points to (a C-style copy of) whatever string you passed to
open_port/2. As far as open_port is concerned, the driver name ends at
the first space (which is quite analogous to / consistent with how the
string is parsed in the case of an external port program, though I
hesitate to mention it...).

> if you load the driver with 
>parameters you just get an "open_error".

Please share the code that gives that result. Of course open_port
doesn't "load the driver", but I assume it's open_port you're talking
about - anyway that's what *I* am talking about. I'm successfully using
the technique I described in commercial product code - in fact it's used
in the OTP code too, e.g. in the dbg module.

>Any other ideas?

None needed.


More information about the erlang-questions mailing list