How to export a new java version path in perl?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anklos
    New Member
    • Sep 2008
    • 30

    How to export a new java version path in perl?

    Hi, everyone~

    I met a problem: the defualt java version on the unix sever is 1.4, but I'd like to export the 1.6 version on the sever (the 1.6 java exists on the sever)

    I wrote the code like this in perl:
    Code:
    system 'export PATH=/usr/java1.6/bin:$PATH';
    It works when I just command "export PATH=/usr/java1.6/bin:$PATH" on the shell, but when I run the code I wrote, the sever reposed me:
    Code:
    sh: PATH=/usr/java1.6/bin:/bin:/usr/bin:/usr/local/bin:/usr/openwin/bin:/usr/bin/X11:/usr/ccs/bin:/opt/SUNWspro/bin:/usr/sbin:/usr/ucb:/usr/sfw/bin:/local/share/bin:.: is not an identifier
    Could anyone help me?
    Thanks a lot in advance.
  • Icecrack
    Recognized Expert New Member
    • Sep 2008
    • 174

    #2
    First please put all code in Code tags,

    2nd. try

    Code:
    system('export PATH=/usr/java1.6/bin:$PATH');
    or

    Code:
    system(`export PATH=/usr/java1.6/bin:$PATH`);
    ----------------------------------------------------------------------------------------------------------

    Code:
    PATH=/usr/java1.6/bin:/bin:/usr/bin:/usr/local/bin:/usr/openwin/bin:/usr/bin/X11:/usr/ccs/bin:/opt/SUNWspro/bin:/usr/sbin:/usr/ucb:/usr/sfw/bin:/local/share/bin:.:
    this happens because $PATH is a Perl ENV var, its set for the path of perl & you are processing that var. to cancel that in perl you must use single quotes ' or ` or cancel that $ by \$PATH.

    Comment

    • anklos
      New Member
      • Sep 2008
      • 30

      #3
      Originally posted by Icecrack
      First please put all code in Code tags,

      2nd. try

      Code:
      system('export PATH=/usr/java1.6/bin:$PATH');
      or

      Code:
      system(`export PATH=/usr/java1.6/bin:$PATH`);
      ----------------------------------------------------------------------------------------------------------

      Code:
      PATH=/usr/java1.6/bin:/bin:/usr/bin:/usr/local/bin:/usr/openwin/bin:/usr/bin/X11:/usr/ccs/bin:/opt/SUNWspro/bin:/usr/sbin:/usr/ucb:/usr/sfw/bin:/local/share/bin:.:
      this happens because $PATH is a Perl ENV var, its set for the path of perl & you are processing that var. to cancel that in perl you must use single quotes ' or ` or cancel that $ by \$PATH.
      Thanks for your reply, but both of your methods dont work. I know $PATH is a perl env var, and I use quotes ' ', if using quotes " ", I have to write code like \$PATH

      Comment

      • Icecrack
        Recognized Expert New Member
        • Sep 2008
        • 174

        #4
        Originally posted by anklos
        Thanks for your reply, but both of your methods dont work. I know $PATH is a perl env var, and I use quotes ' ', if using quotes " ", I have to write code like \$PATH

        But have you tried using backtick's thats `System command`

        example:

        Code:
        system(`export PATH=/usr/java1.6/bin:$PATH`);
        also what errors are you getting or what output.

        try this:

        Code:
        system(`export PATH=/usr/java1\.6/bin:$PATH`);

        Comment

        • anklos
          New Member
          • Sep 2008
          • 30

          #5
          Originally posted by Icecrack
          But have you tried using backtick's thats `System command`

          example:

          Code:
          system(`export PATH=/usr/java1.6/bin:$PATH`);
          also what errors are you getting or what output.

          try this:

          Code:
          system(`export PATH=/usr/java1\.6/bin:$PATH`);
          No, they dont work. I also have another question, if my current directory is /mount/autofs/home_mbc/sniu, and I run code like this:

          Code:
          system 'cd myperl';
          it will repoonse and print out "/mount/autofs/home_mbc/sniu/myperl", but the directory wont change to /mount/autofs/home_mbc/sniu/myperl, it is still /mount/autofs/home_mbc/sniu

          Comment

          • Icecrack
            Recognized Expert New Member
            • Sep 2008
            • 174

            #6
            Originally posted by anklos
            No, they dont work. I also have another question, if my current directory is /mount/autofs/home_mbc/sniu, and I run code like this:

            Code:
            system 'cd myperl';
            it will repoonse and print out "/mount/autofs/home_mbc/sniu/myperl", but the directory wont change to /mount/autofs/home_mbc/sniu/myperl, it is still /mount/autofs/home_mbc/sniu
            also you are using the wrong format for system command its better to use

            Code:
            system(`cd myperl`) || die "$!";
            it depends on the user that your running perl on, does it have access to myperl?

            also are you running perl via CGI or just in CLI ?

            Comment

            • KevinADC
              Recognized Expert Specialist
              • Jan 2007
              • 4092

              #7
              Originally posted by anklos
              No, they dont work. I also have another question, if my current directory is /mount/autofs/home_mbc/sniu, and I run code like this:

              Code:
              system 'cd myperl';
              it will repoonse and print out "/mount/autofs/home_mbc/sniu/myperl", but the directory wont change to /mount/autofs/home_mbc/sniu/myperl, it is still /mount/autofs/home_mbc/sniu
              that will cd in the shell, not in your perl script. Use the chdir() function.

              Comment

              • Icecrack
                Recognized Expert New Member
                • Sep 2008
                • 174

                #8
                Originally posted by KevinADC
                that will cd in the shell, not in your perl script. Use the chdir() function.
                Kevin is right, i'm not awake today,

                also what are you trying to do?

                this will help us more, i know you want to set the path for java but the second topic

                Code:
                system 'cd myperl';

                Comment

                • anklos
                  New Member
                  • Sep 2008
                  • 30

                  #9
                  Originally posted by KevinADC
                  that will cd in the shell, not in your perl script. Use the chdir() function.
                  I see! Thank you !
                  Is that also the same reason that I cant export java version? Because the command is for shell, not for perl script?

                  Comment

                  • KevinADC
                    Recognized Expert Specialist
                    • Jan 2007
                    • 4092

                    #10
                    Originally posted by anklos
                    I see! Thank you !
                    Is that also the same reason that I cant export java version? Because the command is for shell, not for perl script?
                    I believe so. You may want to look at the %ENV variables if you need to add something to perls path environment at run time.

                    Code:
                    $ENV{'PATH'} .= ';/usr/java1.6/bin';

                    Comment

                    • anklos
                      New Member
                      • Sep 2008
                      • 30

                      #11
                      Originally posted by KevinADC
                      I believe so. You may want to look at the %ENV variables if you need to add something to perls path environment at run time.

                      Code:
                      $ENV{'PATH'} .= ';/usr/java1.6/bin';
                      Thanks for your help!

                      Comment

                      Working...