- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to use program to set enviroment in the curre...
Operating System - HP-UX
1753774
Members
7210
Online
108799
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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:19 AM
тАО06-12-2001 05:19 AM
How to use program to set enviroment in the current shell?
I want to develop a program to set enviroment of current shell. I try to use putenv function, but it can only set enviroment on current process. How can I do ? By the way, can complete this task with Java?
Any suggestion is appreciated.
Any suggestion is appreciated.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-12-2001 05:41 AM
тАО06-12-2001 05:41 AM
Re: How to use program to set enviroment in the current shell?
The bad news for you. You cannot change the environment of the curretn process(shell) by calling a child process. That is part of the Unix philosophy, I guess.
The good news. There are some ways around.
1. Source a shell file
( #. shell_script_setting_parameters
2. Set enviroment for a child process.
(# env name=value command)
3. Write your own program simulating env
4. If you want to pass output from a child process and modify environment variables of the parent shell:
from the child process create output on stdout in the form "NAME='value';export NAME".
execute the output "eval $(child_process)"
5. Write output in form of a script to a file and source in file (see. 1.)
Excpecting some points, Klaus
The good news. There are some ways around.
1. Source a shell file
( #. shell_script_setting_parameters
2. Set enviroment for a child process.
(# env name=value command)
3. Write your own program simulating env
4. If you want to pass output from a child process and modify environment variables of the parent shell:
from the child process create output on stdout in the form "NAME='value';export NAME".
execute the output "eval $(child_process)"
5. Write output in form of a script to a file and source in file (see. 1.)
Excpecting some points, Klaus
There is a live before death!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-12-2001 01:02 PM
тАО06-12-2001 01:02 PM
Re: How to use program to set enviroment in the current shell?
Jacklee,
The only thing I can think of doing would be to write a program that does something similar to the following:
#include
#include
void main() {
uid_t uid;
struct passwd *pw;
.
/* Tinker around with your environment here */
.
.
uid = getuid();
pw = getpwuid( pw );
execl( pw->pw_shell, pw->pw_shell );
}
And then exec myprogram. You won't have the SAME shell you started out with, but you'll have a shell (as defined by the /etc/passwd entry) that has all of your new environment variables defined in it.
The only thing I can think of doing would be to write a program that does something similar to the following:
#include
#include
void main() {
uid_t uid;
struct passwd *pw;
.
/* Tinker around with your environment here */
.
.
uid = getuid();
pw = getpwuid( pw );
execl( pw->pw_shell, pw->pw_shell );
}
And then exec myprogram. You won't have the SAME shell you started out with, but you'll have a shell (as defined by the /etc/passwd entry) that has all of your new environment variables defined in it.
I think, therefore I am... I think!
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP