473,386 Members | 2,114 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,386 software developers and data experts.

executing program name

gum
Other than argv[0] is there a way to obtain the name of the executable
programatically?

Feb 1 '06 #1
10 1553
gum wrote:
Other than argv[0] is there a way to obtain the name of the executable
programatically?


AFAIK, no, at least not portable. Why would you want to do it, though?

Cheers

Vladimir

--
Technological progress has merely provided us with more efficient means
for going backwards.
-- Aldous Huxley

Feb 1 '06 #2
In article <aT*******************@tornado.ohiordc.rr.com>,
gum <sf******@yahoo.com> wrote:
Other than argv[0] is there a way to obtain the name of the executable
programatically?


What is the name of the executable that is running your microwave oven?
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton
Feb 1 '06 #3
gum wrote:
Other than argv[0] is there a way to obtain the name of the
executable programatically?


What's wrong with that way?

Brian
Feb 1 '06 #4
gum wrote:
Other than argv[0] is there a way to obtain the name of the executable
programatically?


.... and even argv[0] may be a null pointer.
You may be hard pressed to find argv in the case of a freestanding
implementation.

However, your specific implementation (or: the environment /
operating system) may provide another way. Ask in the respective
newsgroups for more information.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Feb 1 '06 #5
"Vladimir S. Oka" wrote:
gum wrote:
Other than argv[0] is there a way to obtain the name of the
executable programatically?


AFAIK, no, at least not portable. Why would you want to do it,
though?


And even that is not guaranteed. It is system dependant.

--
"The power of the Executive to cast a man into prison without
formulating any charge known to the law, and particularly to
deny him the judgement of his peers, is in the highest degree
odious and is the foundation of all totalitarian government
whether Nazi or Communist." -- W. Churchill, Nov 21, 1943
Feb 2 '06 #6
Walter Roberson wrote:

In article <aT*******************@tornado.ohiordc.rr.com>,
gum <sf******@yahoo.com> wrote:
Other than argv[0] is there a way to obtain the name of the executable
programatically?


What is the name of the executable that is running your microwave oven?


Why, "a.out", of course! :-)

Your microwave may be different. :-)

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Feb 2 '06 #7
Default User wrote:
gum wrote:
Other than argv[0] is there a way to obtain the name of the
executable programatically?


What's wrong with that way?


I can't speak for the OP, but if my "frobnosticator" program had a
line...

fprintf(stderr, "%s: bad vibes!\n", argv[0]);

....then on one system, it might print...

C:\PROGRA~1\FROBNO~1\FROBNO~3.EXE: bad vibes!

So, I generally never use argv[0] as the program name for non-trivial
command line programs.

--
Peter

Feb 3 '06 #8

"Vladimir S. Oka" <no****@btopenworld.com> writes:
gum wrote:
Other than argv[0] is there a way to obtain the name of the executable
programatically?


AFAIK, no, at least not portable. Why would you want to do it, though?


Rather off-topic now, but the question deserves an answer. Here is one
possible reason: a trick that's sometimes used is to create two
different programs out of the same executable file. When the program
starts, it determines from its name which one it is and handles its
input accordingly. This makes sense if the different programs share a
lot of code. It made even more sense in the early days of Unix, when
disk usage must be kept low and so there was actually only one copy on
disk, with "hard links" to the various names. 'mv', 'cp' and 'ln' are
still implemented that way in Solaris.
Feb 3 '06 #9
In article <yz*************@invalid.net>,
Arndt Jonasson <do********@invalid.net> wrote:
"Vladimir S. Oka" <no****@btopenworld.com> writes:
gum wrote:
> Other than argv[0] is there a way to obtain the name of the executable
> programatically?
AFAIK, no, at least not portable. Why would you want to do it, though?
Rather off-topic now, but the question deserves an answer. Here is one
possible reason: a trick that's sometimes used is to create two
different programs out of the same executable file. When the program
starts, it determines from its name which one it is and handles its
input accordingly.

Vladimir's question was, it seems to me, "Why would you want to
find the name of the executable using some method other than argv[0]?"

Straying further:

On systems with unix-like filesystems, there might not -be- one
single name for an executable because multiple directory entries
can point to the same inode (information node). Then there's small
problems like loopback filesystems that introduce cycles into the
name tree...

On VMS, there might only be a single name in one sense, but it would
seldom be the name that you would want, once you have taken into
account clusters and "logicals"... e.g., you -probably- don't want to
resolve the disk prefix all the way back to internal system notation.

On some operating systems, the only meaningful "name" that a file
might have might be its directory slot number, or might be its disk
sector number.

On Windows, you have to decide whether you want the long names
or the short (DOS-compatible) names.

And so on.
--
Prototypes are supertypes of their clones. -- maplesoft
Feb 3 '06 #10
Groovy hepcat Michael Mair was jivin' on Wed, 01 Feb 2006 22:28:33
+0100 in comp.lang.c.
Re: executing program name's a cool scene! Dig it!
gum wrote:
Other than argv[0] is there a way to obtain the name of the executable
programatically?


... and even argv[0] may be a null pointer.


Or it may point at an empty string.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
Feb 4 '06 #11

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

Similar topics

15
by: (Pete Cresswell) | last post by:
I've got a .BAT file that I use for executing various MS Access apps that I wrote way back in the days of 2.0. It's evolved over time, but it still contains a number of possible paths to...
20
by: Neil Robbins | last post by:
I am trying to execute a make table query in my vb.net program. The db that I am accessing is an Access 2000 format db. The SQL code that I am using has been cut and pasted from the SQL View having...
0
by: Rahul Chatterjee | last post by:
Hello All I have designed a dotnet application using VB which basically takes a selection and passes value to a crystal report which in turn passes the value to a Stored procedure. After the...
0
by: BasicQ | last post by:
I am running an executable from my aspx page with the click of a button. A date is passed as an argument. I am able to get the standardoutput from the Process(Exe) into the label of my page after...
7
by: solidsna2 | last post by:
Hi, I am new to using SQL. I want to be able to exucute a query that I place in a view. I want this views to be executed every time a value change in one of the table in a particular field. ...
7
by: tshad | last post by:
I thought I understood how the SaveViewState is working and was trying to use this (as per some code I found) to detect refreshes. It seemed to be working but I found that the SaveViewState was...
5
by: Jose Cintron | last post by:
I created a pretty basic program based on the "Windows Forms Application" template using C++ in VS 2005. When I run the program from my local system it runs properly (do happy dance), now when I...
8
by: lovecreatesbea... | last post by:
K&R 2, sec 2.4 says: If the variable in question is not automatic, the initialization is done once only, conceptually before the program starts executing, ... . "Non-automatic variables are...
2
by: Mark | last post by:
hi, i've written a c++ program that converts one file type to another via two arguments (the input and output filenames). i want to execute this on my server, using something like ...
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:
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.