1. command_line[1], path to the program file, and Linux

Hi,

I need my program to know its own directory -- this seems to me the easiest way
to let it find its ini file, and to define the default directory to which it
writes.

According to the Euphoria documentation, command_line[1] and command_line[2]
both have the complete path to the executable file, and I can easily extract the
path to the directory from there.

It works fine with Windows, but not with Linux -- at least not with Knoppix,
which is the only one I have. Here, command_line[1] and [2] do not contain the
path, but only what I have typed to call the program.

Is this a bug, am I doing something wrong, does this depend on the distribution,
or does it simply not work with Linux/Unix? And if so, is there a workaround?

Thank you!
Robert

new topic     » topic index » view message » categorize

2. Re: command_line[1], path to the program file, and Linux

Robert Schächter wrote:
> 
> Hi,
> 
> I need my program to know its own directory -- this seems to me the easiest
> way to let it find its ini file, and to define the default directory to which
> it writes.
> 
> According to the Euphoria documentation, command_line[1] and command_line[2]
> both have the complete path to the executable file, and I can easily extract
> the path to the directory from there.
> 
> It works fine with Windows, but not with Linux -- at least not with Knoppix,
> which is the only one I have. Here, command_line[1] and [2] do not contain the
> path, but only what I have typed to call the program.
> 
> Is this a bug, am I doing something wrong, does this depend on the
> distribution,
> or does it simply not work with Linux/Unix? And if so, is there a workaround?

Currently, euphoria just passes along whatever the operating system gives
it.  In 3.2, it will do some extra work to give you the full path to the
interpreter.  Juergen (I think?  can't find the post now) posted some code
to do this in Euphoria.  The key is using readlink().

I think that all you'd need to do is:
atom buff, str len
sequence path
constant readlink = define_c_func( open_dll(""), "readlink", 
    {C_POINTER, C_POINTER, C_INT}, C_INT)
buff = allocate( 2048 )
str = allocate_string( "/proc/self/exe" )
len = c_func( readlink, {str, buff})
free( str )
path = peek( {buff, len})
free(buff)


Matt

new topic     » goto parent     » topic index » view message » categorize

3. Re: command_line[1], path to the program file, and Linux

Matt Lewis wrote:
> Currently, euphoria just passes along whatever the operating system gives
> it.  In 3.2, it will do some extra work to give you the full path to the
> interpreter.  Juergen (I think?  can't find the post now) posted some code
> to do this in Euphoria.  The key is using readlink().

Good idea.
I remember wanting to provide the full path on Linux,
but I wasn't sure how to do it.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

4. Re: command_line[1], path to the program file, and Linux

Robert Craig wrote:
> 
> Matt Lewis wrote:
> > Currently, euphoria just passes along whatever the operating system gives
> > it.  In 3.2, it will do some extra work to give you the full path to the
> > interpreter.  Juergen (I think?  can't find the post now) posted some code
> > to do this in Euphoria.  The key is using readlink().
> 
> Good idea.
> I remember wanting to provide the full path on Linux,
> but I wasn't sure how to do it.

Yeah, it's been in there for a bit (check out be_runtime.c).  Thinking back, 
it could have been an email from Juergen, rather than a forum post.

Matt

new topic     » goto parent     » topic index » view message » categorize

5. Re: command_line[1], path to the program file, and Linux

Matt Lewis wrote:

> Robert Craig wrote:
> > 
> > Matt Lewis wrote:
> > > Currently, euphoria just passes along whatever the operating system gives
> > > it.  In 3.2, it will do some extra work to give you the full path to the
> > > interpreter.  Juergen (I think?  can't find the post now) posted some code
> > > to do this in Euphoria.  The key is using readlink().
> > 
> > Good idea.
> > I remember wanting to provide the full path on Linux,
> > but I wasn't sure how to do it.
> 
> Yeah, it's been in there for a bit (check out be_runtime.c).  Thinking back,
> 
> it could have been an email from Juergen, rather than a forum post.

I posted it on Sourceforge, as suggestion for the next Eu version.

Regards,
   Juergen

new topic     » goto parent     » topic index » view message » categorize

6. Re: command_line[1], path to the program file, and Linux

Juergen Luethje wrote:
> 
> I posted it on Sourceforge, as suggestion for the next Eu version.
> 

D'oh!  Of course.  Here's a link to the original:

http://sourceforge.net/tracker/index.php?func=detail&aid=1844641&group_id=182827&atid=902785

Matt

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu