c - using getenv and env doesn't give the same results: -


i have c program prints every environmental variable, name given stdin. prints variables such $path, $user doesn't see environmental variables defined myself in linux shell... instance, in ~.bashrc exported mytest=test_is_working, sourced bashrc (source ~/.bashrc). expected program return test_is_working getenv doesn't.

#include <qcoreapplication> #include <stdio.h> #include <stdlib.h>  int main(int argc, char *argv[]) {     qapplication a(argc, argv);      char* my_env= getenv("mytest");      if(my_env!=null){         printf("my env : %s \n", my_env);     }     else {         printf("can't find env \n");     } return a.exec(); } 

it return : can't find env

while when open terminal , enter “env”, have mytest=test_is_working

i saw similar post: using getenv function solution launch program shell. can't because i'm running , debugging in qtcreator.

i don't know i'm in wrong, explain me?

thanks

  1. environment variable passed child processes started after setting variable. setting them in shell not change in qt creator , programs started it.
  2. qt creator allows customize environment variables (i've seen it).
    check project settings (run section) and/or qt creator properties (it should easy find).
  3. you can set program parameters in qt creator (even redirect standard streams) in project settings, run section.

Comments

Popular posts from this blog

postgresql - Lazarus + Postgres: incomplete startup packet -

c# - How to get the current UAC mode -