- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to use program to set enviroment in the c...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-12-2001 05:16 AM
тАО06-12-2001 05:16 AM
Any suggestion is appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-12-2001 06:00 AM
тАО06-12-2001 06:00 AM
Solution1) In your C program call putenv() to set any needed variables. Make sure that you either declare either global or local static variables
(or do not exit the function invoking the putenv call). You want the areas pointed to by your putenv() to still be defined.
2) From the same C program do a system("/usr/bin/sh");
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-12-2001 06:39 AM
тАО06-12-2001 06:39 AM
Re: How to use program to set enviroment in the current shell?
Create a small shell script that makes the changes to the correct variables, something like this perhaps:
export MY_PATH=~/bin
Name this shell script ~/vars.sh and then, from a shell prompt, type:
. ~/vars.sh
This will run the shell script ~/vars.sh in your *current* shell. Any changes made to the environment in that script will still be visible when ~/vars.sh has completed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-12-2001 11:25 PM
тАО06-12-2001 11:25 PM
Re: How to use program to set enviroment in the current shell?
the other thing you can is, to develop a program that outputs (on stdout) the variables you want to set, and their values. And feed that output to "eval". A small example (bourne or korn shell based - I'm assuming your not using (and will never use) a C-shell):
-----------------------------8<---------------
/* setvar.c */
#include
main (int argc, char **argv) {
puts ("VAR=\"123\"\n");
}
-----------------------------8<---------------
Compile this program, and run it like this:
$ eval `./setvar`, or eval $(./setvar)
HTH, cu l8r, Edgar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2004 08:25 PM
тАО03-25-2004 08:25 PM
Re: How to use program to set enviroment in the current shell?
We want to have a central control program at log on, which looks at user name, checks what he is allowed to run, sets up some environment vars for programs, and run programs from a menu. None of the users are going to see the op sys. How do I get the system set up properly from withing this program? Cant be done readily that I can see.
How does the rest of the world do it? It must be a common requirement surely......for an OPEN system, it sure is hard work.
jp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2004 02:33 AM
тАО03-26-2004 02:33 AM
Re: How to use program to set enviroment in the current shell?
Your requirements are trivially easy. All you have to do is to make your menu executable the user's "shell" in the passwd entry. This executable then does a putenv() to build up as complex as environment as you wish and this each menu selection is a system() command -- this forks() and exec()'s a child process that inherits the environemt. This is classic menu coding.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2004 08:44 PM
тАО03-27-2004 08:44 PM
Re: How to use program to set enviroment in the current shell?
I understand making the menu the user's startup program to keep them out of the OS level. While I am testing it though, I need to be able to see what's going on. Almost anything can be done from the shell level, but the users are not going to have access, so I have to do it all from inside the menu.
jp...still struggling
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2004 07:08 AM
тАО03-28-2004 07:08 AM
Re: How to use program to set enviroment in the current shell?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2004 07:26 AM
тАО03-28-2004 07:26 AM
Re: How to use program to set enviroment in the current shell?
int main(int argc, char *argv[], **envp)
argc = number of arguments in command line
argv = the arguments, e.g. -n 5, argv[0] is a special case; it is the name of the process itself
**envp is an array of environment variables; e.g *envp[1]="HOME=/home/mydir"; the end of this array is signaled by a NULL pointer. Putenv() modifies this array as does the export command in the shell. A COPY of this array is passed to each child process; that is why modifying the child's copy has absolutely no effect upon the parent's version of envp. This is intentional and by design; UNIX ain't MPE.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2004 08:16 PM
тАО03-28-2004 08:16 PM
Re: How to use program to set enviroment in the current shell?
See my notes in thread-52696. Careful reading of man putenv...the envp ptrs , if they contain putenv data, can contain pointers to a parent process' data stack!!! surely this is breach of etiquette, if not security??
jp