<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to set environment variables using C/C++ through PERL script in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/how-to-set-environment-variables-using-c-c-through-perl-script/m-p/4085073#M92108</link>
    <description>Hi All,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;    But, putenv amd getenv will work inside the program. Because i think when we execute a C/C++ program separate process is started then whatever ssettings we do will be there in that Process. So after completion of execution if i do &lt;BR /&gt;&lt;BR /&gt;       echo $HELLO&lt;BR /&gt;&lt;BR /&gt;where "Hello=Hai" string is present ia file and this string i am reading from that file.&lt;BR /&gt;&lt;BR /&gt;  Is there any way i can achieve this.&lt;BR /&gt;&lt;BR /&gt;   This i want because we already have a PERL script that is generating the file containing the environment variable list.&lt;BR /&gt; Can any body please help me out of this Problem.&lt;BR /&gt;&lt;BR /&gt;thanks and regards&lt;BR /&gt;Vikram</description>
    <pubDate>Fri, 12 Oct 2007 09:37:25 GMT</pubDate>
    <dc:creator>CA1490051</dc:creator>
    <dc:date>2007-10-12T09:37:25Z</dc:date>
    <item>
      <title>How to set environment variables using C/C++ through PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-set-environment-variables-using-c-c-through-perl-script/m-p/4085070#M92105</link>
      <description>Hi All,&lt;BR /&gt;&lt;BR /&gt;     I want to run a PERL script through my C/C++ code. In the PERL script i am generating a SHELL script that sets some environment variables. As discussed previously in the thread, &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; But, now my question is can we run this PERL script through the C/C++ code. Because i think it is not possible to run an executable as Source (Please correct me if i am wrong).&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1164715" target="_blank"&gt;http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1164715&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt; Please let me know the solution for this.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;thanks in advance&lt;BR /&gt;Vikram</description>
      <pubDate>Thu, 11 Oct 2007 23:37:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-set-environment-variables-using-c-c-through-perl-script/m-p/4085070#M92105</guid>
      <dc:creator>CA1490051</dc:creator>
      <dc:date>2007-10-11T23:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to set environment variables using C/C++ through PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-set-environment-variables-using-c-c-through-perl-script/m-p/4085071#M92106</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;you're right - this is not possible.&lt;BR /&gt;But since you already create a file for the environment variables and theier values:&lt;BR /&gt;Just create them in the form&lt;BR /&gt;var1=value for it&lt;BR /&gt;var2=other value for that&lt;BR /&gt;&lt;BR /&gt;Then in your C-code read this file line-by-line and feed the string into putenv().&lt;BR /&gt;Codefragment (no error checking):&lt;BR /&gt;&lt;BR /&gt;FILE *ef = fopen("envfile","r");&lt;BR /&gt;char str[128];&lt;BR /&gt;while (fgets(str,127,ef) putenv(str);&lt;BR /&gt;fclose(ef);&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Fri, 12 Oct 2007 05:55:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-set-environment-variables-using-c-c-through-perl-script/m-p/4085071#M92106</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2007-10-12T05:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to set environment variables using C/C++ through PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-set-environment-variables-using-c-c-through-perl-script/m-p/4085072#M92107</link>
      <description>If you call perl (system? fork?)  then you are in a different prcoess once in perl.&lt;BR /&gt;You can set all the environment variables you like for that process, but they will not be visible to the current process running the C code.&lt;BR /&gt;&lt;BR /&gt;WHY do you think you need to go trhough perl to sh to do this?&lt;BR /&gt;&lt;BR /&gt;WHAT is the value the perl step adds?&lt;BR /&gt;&lt;BR /&gt;WHY not do it all directly in the C program, callign putenv?&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 12 Oct 2007 06:43:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-set-environment-variables-using-c-c-through-perl-script/m-p/4085072#M92107</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-10-12T06:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to set environment variables using C/C++ through PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-set-environment-variables-using-c-c-through-perl-script/m-p/4085073#M92108</link>
      <description>Hi All,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;    But, putenv amd getenv will work inside the program. Because i think when we execute a C/C++ program separate process is started then whatever ssettings we do will be there in that Process. So after completion of execution if i do &lt;BR /&gt;&lt;BR /&gt;       echo $HELLO&lt;BR /&gt;&lt;BR /&gt;where "Hello=Hai" string is present ia file and this string i am reading from that file.&lt;BR /&gt;&lt;BR /&gt;  Is there any way i can achieve this.&lt;BR /&gt;&lt;BR /&gt;   This i want because we already have a PERL script that is generating the file containing the environment variable list.&lt;BR /&gt; Can any body please help me out of this Problem.&lt;BR /&gt;&lt;BR /&gt;thanks and regards&lt;BR /&gt;Vikram</description>
      <pubDate>Fri, 12 Oct 2007 09:37:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-set-environment-variables-using-c-c-through-perl-script/m-p/4085073#M92108</guid>
      <dc:creator>CA1490051</dc:creator>
      <dc:date>2007-10-12T09:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to set environment variables using C/C++ through PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-set-environment-variables-using-c-c-through-perl-script/m-p/4085074#M92109</link>
      <description>Hi Vikram:&lt;BR /&gt;&lt;BR /&gt;This thread (as you noted) is a continued discussion of your previous thead.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; ...we already have a PERL script that is generating the file containing the environment variable list.&lt;BR /&gt;&lt;BR /&gt;Then, in your C/C++ program read the generated file of environmental variables; parse the variable and associated value and issue 'putenv' calls.&lt;BR /&gt;&lt;BR /&gt;Peter, in fact, has already shown a code snippet to do this.  His C/C++ suggestion is the same as my shell suggestion in you earlier thread.  There isn't any more magic here.  Let your Perl script generate a common environmental configuration file for you shell process (in shell syntax) and let your C/C++ program conform to parsing and using that format to apply 'putenv' calls.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 12 Oct 2007 09:55:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-set-environment-variables-using-c-c-through-perl-script/m-p/4085074#M92109</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-10-12T09:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to set environment variables using C/C++ through PERL script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-set-environment-variables-using-c-c-through-perl-script/m-p/4085075#M92110</link>
      <description>If I under stand your question then the answer is no and thankfully no one can help you out of this --- and it is a very good thing that they can't. You want the enviroment of a child process to be inherited by a parent process. The child process inherits the parent's environment not the other way round.&lt;BR /&gt;&lt;BR /&gt;Your Perl script could do something like write to stdout a series of strings "AAA=aaa\n","BBB=bbb\n", .... and if your Perl script were called by popen() for example, it would be able to then call putenv() using each of these strings. That (or a similar scheme using a temporary file) is the only way a child can alter a parent's environment because it is doing it indirectly.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 12 Oct 2007 10:02:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-set-environment-variables-using-c-c-through-perl-script/m-p/4085075#M92110</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-10-12T10:02:09Z</dc:date>
    </item>
  </channel>
</rss>

