Re: How can I retrieve the full path of running exe



On Jun 21, 12:39 pm, rober...@xxxxxxxxxxxxxxxxxx (Walter Roberson)
wrote:
In article <1182409466.377219.97...@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,

<somank.sha...@xxxxxxxxx> wrote:
I am running an exe created in C. I need the full path (absolute path)
of this exe. In the first argument of main, I am getting the exe name.
How can I get the full path for this exe.

There is no portable way to do that.

The C language doesn't even promise that the first argument of main
will have any form of the executable name. (This fact is actively
used in many Unix operating systems.)

Some versions of *some* operating systems provide mechanisms that
do what you want, but they are not necessarily simple to use,
and the path retrieved might be -some- absolute path to reach
the executable rather than the one that was actually used to
invoke it. Details are operating system version dependant, so you
will need to ask in a newsgroup appropriate for your operating system.

(It's not uncommon for it to be pretty messy when it is possible at all.
Messy enough that OS gurus might think it isn't possible when really
it might only take about 3/4 of an hour of investigative work rooting
around in the operating system internals. Or it might be doable on
some operating systems if you devoted a week to it. But it
is completely impossible on some operating systems.)
--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes

Refer getcwd(3) man page.
get_current_dir_name() returns the current working directory of
running exe.

.



Relevant Pages

  • Re: How can I retrieve the full path of running exe
    ... In the first argument of main, I am getting the exe name. ... and the path retrieved might be -some- absolute path to reach ... invoke it. ... will need to ask in a newsgroup appropriate for your operating system. ...
    (comp.lang.c)
  • Re: How can I retrieve the full path of running exe
    ... In the first argument of main, I am getting the exe name. ... and the path retrieved might be -some- absolute path to reach ... invoke it. ... will need to ask in a newsgroup appropriate for your operating system. ...
    (comp.lang.c)
  • Re: VB.NET, you must be desperate if you use it
    ... This is bordering stupidity... ... You can write programs that work on every operating system and that work on ... Only one major operating system vendor uses the exe format... ... I don't hold much credibilty to your business knowledge. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: running a second *.exe while one *.exe is running using Lahey fortran
    ... Use the Windows START command. ... -|I am using using Window 2000 operating system and running *.exe using ... How do I write fortran program for this situation? ...
    (comp.lang.fortran)
  • Re: Date
    ... In OS 10.3 and 10.4, by default, the operating system takes precedence and ... allocates the F9 key with modifiers to invoke one of the Exposé features. ... reassigning the field commands in Word: ...
    (microsoft.public.mac.office.word)