1. command_line[1], path to the program file, and Linux
- Posted by Robert Schächter <drs at drs.a?> Jan 07, 2008
- 650 views
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
2. Re: command_line[1], path to the program file, and Linux
- Posted by Matt Lewis <matthewwalkerlewis at ?mail?com> Jan 07, 2008
- 647 views
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
3. Re: command_line[1], path to the program file, and Linux
- Posted by Robert Craig <rds at R?pidEuphoria?com> Jan 07, 2008
- 635 views
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
4. Re: command_line[1], path to the program file, and Linux
- Posted by Matt Lewis <matthewwalkerlewis at gmai?.com> Jan 07, 2008
- 637 views
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
5. Re: command_line[1], path to the program file, and Linux
- Posted by Juergen Luethje <j.lue at gm?.de> Jan 07, 2008
- 652 views
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
6. Re: command_line[1], path to the program file, and Linux
- Posted by Matt Lewis <matthewwalkerlewis at gm?il.c?m> Jan 07, 2008
- 662 views
- Last edited Jan 08, 2008
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