By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,157 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

Username of Caller

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.