Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1910
  • Last Modified:

Passing arguments / setting environment variables for a perl script

HI,
I am new to perl script and need to run  a perl script  found at the following URL  http://ximbiot.com/cvs/cvshome/cyclic/cvs-html/dev-pvcs_to_rcs.pl

Please tell me how to set the environment variables / passing arguments to this script file.
I have already installed Active Perl 5.8.8 Build 817 on Windows.

Looking for some early response from PERL evangelists
Thanks in advance
Vaneet
0
CRISIL
Asked:
CRISIL
  • 9
  • 5
  • 4
  • +2
4 Solutions
 
Suhas .QA ManagerCommented:
to determine the setting of your "PATH" environment variable, you can just do something like this:

   $path = $ENV{'PATH'};


example:
 #!/usr/bin/perl

   $ENV{'PATH'} = '/bin:/usr/bin:/home/fred/bin';
   print $ENV{'PATH'};


To get the command line arguments inside script:

@ARGV

i.e., $ARGV[0] filename
$ARGV[1] first argument
$ARGV[2] second argument etc...

to run a file:
>perl filename
0
 
CRISILAuthor Commented:
Hi,
Thanks for responding so quickly.
When i am tring to run this file using the command
perl dev-pvcs_to_rcs.pl
It is giving me the following error-

----------------ERROR----------------------------------------------------------------------------------
'which' is not recognized as an internal or external command,
operable program or batch file.
'which' is not recognized as an internal or external command,
operable program or batch file.
'which' is not recognized as an internal or external command,
operable program or batch file.
'which' is not recognized as an internal or external command,
operable program or batch file.
The following executables were not found in your PATH: vcs vlog rcs ci
You must correct this before continuing.

-----------------------------------------------------------------------------------------------------------------

Not able to understand it .
Please guide  me

Thanx & Regards
Vaneet
0
 
Suhas .QA ManagerCommented:
Please can you get clarify with :

if (system "which", $_)
{
            push @missing_binaries, $_;
}

# here you are passing the program name "which" with arguments.

what kind of program that "which"

also go through more about system:

http://www.perlmonks.org/?node=perlfunc%3Asystem

Regards,
Suhas
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
CRISILAuthor Commented:
Hi Subhas,
Actually , i am new to perl script , so dont understand the perl code properly.
I will give u an idea what this script does .
Basically i want to migrate some code from one  source control system to another source control sytem i.e i want to migrate the repository from PVCS to RCS system .
So , i think this script will take some inputs like
1) location of the PVCS repository
2) New location where the code wiill be migarted i.e RCS repository

This is what i am able to understand from this script file.
 I hope probably , you can guide me more on this
Really looking forward to your assistance.

Thanks & Regards
Vaneet
0
 
Suhas .QA ManagerCommented:
Have you included the environment variable  for vcs vlog rcs ci ?

0
 
CRISILAuthor Commented:
No,
How to do that ?
0
 
Suhas .QA ManagerCommented:
You should set these environment variables (with SETENV for the C shell or EXPORT for the SH or KSH shells)
0
 
CRISILAuthor Commented:
what is the synatx of setting environment variables ?
Can i, do this from command prompt in WIndows.

0
 
CRISILAuthor Commented:
Hi Subhas,
I have few doubts on the following lines in the script

--------------------------------------------------------------------------------------
# The binaries this script is dependant on:
my @bin_dependancies = ("vcs", "vlog", "rcs", "ci");
# Where we should put temporary files
my $tmpdir = $ENV{TMPDIR} ? $ENV{TMPDIR} : "/var/tmp";
-----------------------------------------------------------------------------------------

Kindly tell, how can i set the dependencies on the first line.
and how do i set the location of temporary directory in the script.
Can i hard code it ?
And how do i set through command line .....

Thanx  & Regards
Vaneet
0
 
TalmashCommented:
setting dependencies:
setenv TMPDIR kuku; dev-pvcs_to_rcs.pl

hardcode :
my $tmpdir = "/var/tmp"; # I removed the condition for external seting

setting through command line:
dev-pvcs_to_rcs.pl kuku
..
my $tmpdir = $ARGV[1]; # the 1st argument in command line following the script's name

Tal

0
 
CRISILAuthor Commented:
Hi Tal,

When i tried running your command    setenv TMPDIR kuku; dev-pvcs_to_rcs.pl
It gave the following error on the command promompt
-------------------------------------------------------------------------------------
C:\>setenv TMPDIR kuku; dev-pvcs_to_rcs.pl
'setenv' is not recognized as an internal or external command,
operable program or batch file.
----------------------------------------------------------------------------------------
Also talking about the path name for the temp directory , does that path name should be relative or absolute.

How can i pass all the dependencies mentioned at the following line
----------------------------------------------------------------------------------
# The binaries this script is dependant on:
my @bin_dependancies = ("vcs", "vlog", "rcs", "ci");
-----------------------------------------------------------------------------------

Thanks & Regards
Vaneet
0
 
Adam314Commented:
The commands given so far (as well as the paths) are unix style, but you are on windows....

To set an environment variable, at a command prompt:
set <variable_name>=<variable_value>

So to set the temp directory to c:\temp (set it to something that exists!):
    set TMPDIR=c:\temp

Then these program are used by the script: vcs vlog rcs ci
Do you have these installed?  If not, you will need to install them before using this script.
If you do have them installed, the script was not able to find them.  To help the script find them, you need to include their path in your PATH variable.
If, for example, the vcs program is located at C:\Program Files\Version Control System\bin\vcs.exe, you would add C:\Program Files\Version Control System\bin to your path using:
    set path=%path%;C:\Program Files\Version Control System\bin

To find where they may be located, you can use windows search feature.
0
 
Adam314Commented:
I was just looking at the code, and there are commands in there that will NOT work under windows.
Specifically the hit_any_key function.  It uses the stty program to read a single character from the keyboard.

You can change it like so:
sub hit_any_key
{
    print "Press Return or Enter to continue...";
    my $garbage=<STDIN>;
}


0
 
Adam314Commented:
Sorry for multiple posts.....
I also just noticed the method it uses to look for the binaries uses the "which" program, which does not exist on windows.  If you are sure you have the binaries installed, you can remove that logic.
0
 
CRISILAuthor Commented:
Hi Adam,

Thanx a ton for looking at my script.
Adam i will be setting the path variable for vcs vlog rcs ci scripts.
I have few queries regarding my script
1)How can i set the path of my PVCS repository
2) How can i set the path of my destination repository (RCS repository)
3) Can i run this script on some unix emulator on my WIndows machine ? If yes please suggest some emulator for windows.
4) Please elaborate more on "which" program

Thanx & Regards
Vaneet
0
 
Adam314Commented:
4) The "which" program is a program common on unix systems that will tell you the location of another program.
So if you typed "which ls" (ls is similiar to "dir" in windows), it would come back with "/usr/bin/ls"
If windows had which, and you typed "which excel.exe", it would come back with "C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE"
The script is using the which program to determine if and where the binaries vcs vlog rcs and ci are located.

3) The script says it was tested on solaris.  You could try running it on cygwin:
http://www.cygwin.com/
I'm not sure if the binaries, vcs vlog rcs ci, would work as expected though.  I think you'd have to try it to find out.
A few minor changes to the script and you should be able to run it on windows though.

1 and 2) It looks like you should be in the PVCS directory, and it will put the files in an RCS directory one level up.
Eg:
C:\Repositories\VCS      This is the PVCS directory, run script from this directory
C:\Repositores\RCS       This is where the new files will go
0
 
mjcoyneCommented:
I think using the "set" command only sets the environmental variable temporarily -- when you close the DOS command line box, the variables you added cease to exist.  If you'd like to set the variables permanently, right-click on My Computer, and select the properties menu option.  On the System Properties dialog that appears, click on the Advanced tab.  Click on the button labeled Environment Variables, and you can see all the current (pre-defined) variables in your environment.  Using the New button in the System variables pane of the Environmental Variables dialog box, you can add new variables to your environment that will presist. These instructions are for XP; your mileage may vary with other Windows versions.

Another option for running *NIX scripts and applications on Windows is virtualization.  At work, I run Fedora 7 (and several other OSes and apps) as a virtual appliance (see http://www.vmware.com/vmtn/appliances/directory/) under Windows XP using the free VMWare Player (see http://www.vmware.com/products/player/).
0
 
CRISILAuthor Commented:
Hi,
I installed the unix emulator cygwin and tried running the script.
Although i have set the environment variable 'path' correctly, but still it is not able to find the rcs and ci scripts.
When i try to print the environmnet variable path in cygwin ,using the following script
------------------------
print $ENV{'PATH'};
-------------------------

Its not showing the location for rcs and ci scripts.
Please tell me what can be wrong.
0
 
CRISILAuthor Commented:
Hi Adam,

If i am running this script in cygwin , do i need to make any changes in the script.
If yes, please tell me what i need to change in this script.

Thanks & Regards
Vaneet Sharma
0
 
mjcoyneCommented:
In cygwin, you're working in a Unix environment again.  The path file in cygwin is in something like c:\cygwin\etc\profile.  You can edit this file with a text editor, and add whatever directories you need to to your cygwin path, separated by full colons (:), e.g.:

PATH="/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:.:$PATH
0
 
Adam314Commented:
I'm not familiar with with script or the VCS or RCS version control systems, so I can't say for sure.  The problems with the script I pointed out were obviously not going to work on windows.  I don't see anything that should prevent it from working though.

You'll have to update your path as mjcoyne said so that all of the binaries are found.  If you run the script, and it doesn't find all of them, it will give you a warning message.
If you seem to have the path to the binaries correct, and the script still doesn't find them, you might need to make a copy of <name>.exe to just <name>.  Unix doesn't use an .exe extension for executable files.  I'm not sure if cygwin will take care of that automatically or not.
So, for example, if you have "vcs.exe", make a copy called "vcs" in the same directory.
0
 
mjcoyneCommented:
Or go with virtulaization -- then you'd be running a native OS, rather than an emulator, and the script will likely work as is.  Cygwin is a good solution, but it *is* an emulator -- running a *NIX OS as a virtual machine is much more "native"...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 9
  • 5
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now