473,387 Members | 1,548 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.

Username of Caller

I need to write a file to the bin directory of the user who is calling
my installer. I am running this on IBM's AIX OS with ksh. Is there a
way to do this without using system() to execute whoami?

Aug 10 '07 #1
9 1850
TWalsh wrote:
I need to write a file to the bin directory of the user who is calling
my installer. I am running this on IBM's AIX OS with ksh. Is there a
way to do this without using system() to execute whoami?
Huh? Don't you think that this is better asked in AIX OS newsgroup?
'system' function is platform-specific, not to mention that it's most
likely not the right tool for the job. There are probably mechanisms
in the OS to query the information about the user.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 10 '07 #2
I am converting a shell script to C++. I already know how to find the
calling user's username in a shell script, which is just the whoami
command. I need to know if there is a way to find either the calling
user's username or the calling users home directory in C++.

I know one way to do this would be to call system() from stdlib.h and
save the result into a file but that is a horrible solution.

Aug 10 '07 #3
Hi!

TWalsh schrieb:
I am converting a shell script to C++. I already know how to find the
calling user's username in a shell script, which is just the whoami
command. I need to know if there is a way to find either the calling
user's username or the calling users home directory in C++.
I think you missed the point. This newsgroup is for C++. Altough you are
writing a C++ program, not all question go here. The C++ standard (which
this newsgroup is about) contains nothing about users home dirs. This is
why we cannot help you here.

Anyway, the operating system you are targeting may supply functions
which do what you want. The knowledge about these functions is not
covered here. You should look for a specific other newsgroup which
covers system calls of AIX OS. My guess goes to comp.unix.aix .

If nothing helps try to read the source code of "whoami".

My 2cents: I guess not all home dirs are "/home/username". I hope there
is a function to retrieve the complete correct path directly.

Frank
Aug 10 '07 #4
On 2007-08-10 19:55, TWalsh wrote:

First of all, please quote the text you are replying to.
I am converting a shell script to C++. I already know how to find the
calling user's username in a shell script, which is just the whoami
command. I need to know if there is a way to find either the calling
user's username or the calling users home directory in C++.
The concept of user does not exist in standard C++ since not all
platforms where you can use C++ on have users (does not really make much
sense when programming the injection-system of a combustion-engine does
it?).
I know one way to do this would be to call system() from stdlib.h and
save the result into a file but that is a horrible solution.
Take a look at the getenv() function from <cstdlib>, and use it to get
the path to the home directory, that's how your shell does it when you
do cd ~.
--
Erik Wikström
Aug 10 '07 #5
Take a look at the getenv() function from <cstdlib>, and use it to get
the path to the home directory, that's how your shell does it when you
do cd ~.
I had just found that unix defines $HOME as an environment variable
and was going to post for completeness. Thanks for the help.

Aug 10 '07 #6

"TWalsh" <wa****@gmail.comwrote in message
news:11**********************@m37g2000prh.googlegr oups.com...
>I am converting a shell script to C++. I already know how to find the
calling user's username in a shell script, which is just the whoami
command. I need to know if there is a way to find either the calling
user's username or the calling users home directory in C++.

I know one way to do this would be to call system() from stdlib.h and
save the result into a file but that is a horrible solution.
[OT}
On a Unix platform, try getuid()
With Motif, XmeGetHomeDirName()
or try getenv("HOME")
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Aero Stability and Controls Computing
Aug 10 '07 #7
TWalsh wrote:
I need to write a file to the bin directory of the user who is calling
my installer. I am running this on IBM's AIX OS with ksh. Is there a
way to do this without using system() to execute whoami?
Still off topic, however, you may look at the environment variables like
PATH, USER, USERNAME, HOME etc. These or at least some are cross platform.

BTW - there is no "standard" bin directory for a particular user.

getenv *IS* standard c++.

Aug 10 '07 #8
On Aug 10, 7:45 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
TWalsh wrote:
I need to write a file to the bin directory of the user who is calling
my installer. I am running this on IBM's AIX OS with ksh. Is there a
way to do this without using system() to execute whoami?
Huh? Don't you think that this is better asked in AIX OS newsgroup?
'system' function is platform-specific, not to mention that it's most
likely not the right tool for the job. There are probably mechanisms
in the OS to query the information about the user.
A general Unix group would be OK as well. (But as Gianni said,
there is no bin directory of a user under Unix, unless that user
has decided to create one.)

--
James Kanze (GABI Software) email:james.ka...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Aug 11 '07 #9

I know this is off topic but I thought I would help. I have
a multi-platform solution that works on both Windows and
Redhat Linux. See below code:
#ifdef WIN32
#include <stdlib.h>
#else //LINUX
#include <pwd.h>
#include <unistd.h>
#endif

std::string getUsername()
{
std::string username;
#ifdef WIN32
const char* getenvStr = ::getenv("Username");
if (getenvStr != 0)
{
username = getenvStr;
}
#else //LINUX
struct passwd *userinfo;
userinfo = getpwuid(getuid() );
username = userinfo->pw_name;
#endif
return username;
}

Aug 13 '07 #10

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

Similar topics

7
by: ivan_oj28 | last post by:
Hi, I am developing an application where I need to read the caller id from an incoming call. The only info (for now) I need is the caller id info, so that I can display the propper caller info on...
1
by: Matthew Houseman | last post by:
All, What's the accepted best practice for persisting data? Commit by the PL/SQL or commit by the caller (C#, Java, VB, etc.). I believe that if the caller starts a transaction and calls...
9
by: jaden10001 | last post by:
I have read that the function.caller method is now depricated. I see alot of browsers still support it but Opera 7 does not. Is there a way to get the name of the caller of a function in Opera 7?
4
by: Thomas Mlynarczyk | last post by:
Hi, I stumbled over a strange behaviour of Mozilla. When I want to access the caller property of a function that was not called from within another function, Mozilla seems to abort the script....
4
by: 1qa2ws | last post by:
Hi, I need to get the windows current logged username and domain. Is it any possibility? 1qa2ws
9
by: Csaba Gabor | last post by:
Inside a function, I'd like to know the call stack. By this I mean that I'd like to know the function that called this one, that one's caller and so on. So I thought to do: <script...
4
by: kvicky | last post by:
I am trying to set a scheduled task for one of my ASP.net application that I developed on a monthly basis. This application requires a login authentication. I am sending the url of the login page...
7
by: Rahul | last post by:
Hi Everyone, I have a function utility() which is a part of a library and i would like to know as to who is invoking the function. I could request that information as a parameter enumeration,...
7
by: =?UTF-8?B?QW50w7NuaW8gTWFycXVlcw==?= | last post by:
Hi, Sorry if this's been discussed before, I couldn't find it. As well you know, the ECMAScript standard doesn't include any way to access a function's caller. This has been available on Mozilla...
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.