By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,691 Members | 1,997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,691 IT Pros & Developers. It's quick & easy.

How to export a new java version path in perl?

P: 30
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:
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. 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.
Sep 29 '08 #1
Share this Question
Share on Google+
10 Replies


Icecrack
Expert 100+
P: 174
First please put all code in Code tags,

2nd. try

Expand|Select|Wrap|Line Numbers
  1. system('export PATH=/usr/java1.6/bin:$PATH');
or

Expand|Select|Wrap|Line Numbers
  1. system(`export PATH=/usr/java1.6/bin:$PATH`);
----------------------------------------------------------------------------------------------------------

Expand|Select|Wrap|Line Numbers
  1. 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.
Sep 29 '08 #2

P: 30
First please put all code in Code tags,

2nd. try

Expand|Select|Wrap|Line Numbers
  1. system('export PATH=/usr/java1.6/bin:$PATH');
or

Expand|Select|Wrap|Line Numbers
  1. system(`export PATH=/usr/java1.6/bin:$PATH`);
----------------------------------------------------------------------------------------------------------

Expand|Select|Wrap|Line Numbers
  1. 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
Sep 29 '08 #3

Icecrack
Expert 100+
P: 174
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:

Expand|Select|Wrap|Line Numbers
  1. system(`export PATH=/usr/java1.6/bin:$PATH`);
also what errors are you getting or what output.

try this:

Expand|Select|Wrap|Line Numbers
  1. system(`export PATH=/usr/java1\.6/bin:$PATH`);
Sep 29 '08 #4

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

example:

Expand|Select|Wrap|Line Numbers
  1. system(`export PATH=/usr/java1.6/bin:$PATH`);
also what errors are you getting or what output.

try this:

Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1. 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
Sep 30 '08 #5

Icecrack
Expert 100+
P: 174
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:

Expand|Select|Wrap|Line Numbers
  1. 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

Expand|Select|Wrap|Line Numbers
  1. 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 ?
Sep 30 '08 #6

KevinADC
Expert 2.5K+
P: 4,059
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:

Expand|Select|Wrap|Line Numbers
  1. 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.
Sep 30 '08 #7

Icecrack
Expert 100+
P: 174
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

Expand|Select|Wrap|Line Numbers
  1. system 'cd myperl';
Sep 30 '08 #8

P: 30
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?
Sep 30 '08 #9

KevinADC
Expert 2.5K+
P: 4,059
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.

Expand|Select|Wrap|Line Numbers
  1. $ENV{'PATH'} .= ';/usr/java1.6/bin';
Sep 30 '08 #10

P: 30
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.

Expand|Select|Wrap|Line Numbers
  1. $ENV{'PATH'} .= ';/usr/java1.6/bin';
Thanks for your help!
Oct 1 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.