I asked this before, but I have to ask again considering I still haven't found a way to do this. I need to know if there's a way to take a variable inputted into a C++ program and pass it to the terminal as an environment variable. Again, I'm running Ubuntu if it matters.

Recommended Answers

All 2 Replies

you have a couple options

1) call setenv() function. The variable will disappear when the c++ program exits.

2) write a shell program to call your program and capture its return variable. Then return the value of the variable from main() so that the shell program can grab it and set the environment variable. Remember that the shell program will have to export the variable ot it will disappear when the shell program terminates.

Thank you so much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.