473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How can I retrieve the full path of running exe

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.

Jun 21 '07 #1
4 3008
In article <11*********************@w5g2000hsg.googlegroups.c om>,
<so***********@gmail.comwrote:
>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
Jun 21 '07 #2
On Jun 21, 12:39 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
In article <1182409466.377219.97...@w5g2000hsg.googlegroups.c om>,

<somank.sha...@gmail.comwrote:
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.

Jun 21 '07 #3
ga*************@gmail.com wrote:
On Jun 21, 12:39 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
>In article <1182409466.377219.97...@w5g2000hsg.googlegroups.c om>,

<somank.sha...@gmail.comwrote:
>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.
(a) that's a Linux/Unix/Posix thing: it's OS-dependent.

(b) it's also irrelevant. The OP asked for the full path name of
the running executable, not the full path name of the process
in which it's running.

(c) snip signatures.

--
Chris "didn't get to D" Dollin

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

Jun 21 '07 #4
"ga*************@gmail.com" <ga*************@gmail.comwrites:
On Jun 21, 12:39 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
>In article <1182409466.377219.97...@w5g2000hsg.googlegroups.c om>,
<somank.sha...@gmail.comwrote:
>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.)
[snip]
Refer getcwd(3) man page.
get_current_dir_name() returns the current working directory of
running exe.
Walter's answer, that there is no portable way to do that, is correct.
The getcwd function is system-specific -- and it doesn't do what the
original poster was asking about anyway.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 21 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Peter Kaptein | last post by:
I am building websites using Databases and COM for 3tier apps. Currently I have to tell my COM object where the database is located either 1) Hardcoded in the DLL 2) Via my ASP call How do...
6
by: JuLiE Dxer | last post by:
Is there a way via C# to programmatically retrieve the full path name to folders like "My Documents" ?? I'm seeing examples with the use of Shell32 stuff I believe, SHGetSpecialFolderLocation...
2
by: Sridhar | last post by:
Hi, I have a web form where it has a <input type=file id=file1> control. I have an Upload button to upload the file. WHen I click on browse and select one file, it is showing the full file path...
7
by: gmax2006 | last post by:
Hi, I use RedHat linux. How can I find where exactly the current python script is running? I use this code: #test.py import os,sys
13
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end...
2
by: sandhya2006 | last post by:
In Perl how to retrieve the full path of a file.If the file is in c:/s/fir.pl then i have to know the code for displaying this path in a text.Is anyone can help me.
1
by: somank.sharma | last post by:
Hi All, I am running an exe which is written in C. In the main method of this exe I am getting the exe name as the first argument argv, I want the full path of this exe. How can I retrieve this?...
2
by: tvjraman | last post by:
I've spent two days on google trying to find a suitable solution for getting the full path of the running process but in vain. My question is very simple. I want to know the full path of the...
3
by: =?Utf-8?B?RGV2b24=?= | last post by:
Is it possible to retrieve a proper/invariant file or directory name using a lowercase full path string without having to resort to a call to GetDirectories()/GetFiles() using the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.