set environment in perl through windows

Discussion in 'Perl Misc' started by Slickuser, Jun 13, 2009.

  1. Slickuser

    Slickuser Guest

    I want to set a permanent environment on Windows and use it right
    away.
    None of this work, any help?

    system("SET A=c");
    system("SETX AB BN");

    system("echo %A%");
    print $ENV{'A'} . $ENV{'AB'};

    From the above script.. i got nothing print out

    Output:
    %A%
     
    Slickuser, Jun 13, 2009
    #1
    1. Advertising

  2. Slickuser <> wrote:
    >I want to set a permanent environment on Windows and use it right
    >away.
    >None of this work, any help?
    >
    >system("SET A=c");


    Starts a new process, executes the SET command in that process, and then
    terminates that process.

    >system("SETX AB BN");


    Starts a different new process, executes the SETX command in that
    process, and terminates that process.

    >system("echo %A%");


    Starts yet a third new process, executes the echo command in that
    process, and terminates that process.

    >print $ENV{'A'} . $ENV{'AB'};


    And then prints the values of the environment variables A and AB as they
    are set in the process, which is executing the Perl program and which
    has nothing to do with the three earlier child processes..

    If you want to set an environment variable in your Perl program/Perl
    process then just do so:

    $ENV{'A'} = 'c';
    $ENV{'AB'} = 'BN';

    Of course these settings will not be inherited by the parent process,
    i.e. by the process that initiated the Perl process. If that's what you
    had in mind then I suggest to consult
    perldoc -q environment

    jue
     
    Jürgen Exner, Jun 13, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim
    Replies:
    3
    Views:
    568
  2. Fuzzyman

    Set Windows Environment Variable

    Fuzzyman, Mar 30, 2006, in forum: Python
    Replies:
    6
    Views:
    8,645
    Fuzzyman
    Mar 30, 2006
  3. Replies:
    5
    Views:
    680
  4. chandan
    Replies:
    1
    Views:
    318
  5. Replies:
    1
    Views:
    117
    Bart Lateur
    Mar 18, 2007
Loading...

Share This Page