Posted by: ibmadmin | January 21, 2012

Hard Links to run PERL program – Shebang line equivalent in Windows OS

How To Run PERL Program in Windows And UNIX OS

 

Shebang Line

The PERL programming help system administrators and middleware administrators to simplify their day-today administration work.  Under the UNIX environment, the program execution (i.e. shell or C or PERL program) is determinded by the first line of the program.  This is called “the shebang line” in Shell / Perl culture, or alternately the “sharpbang” or the “hash-bang”. The following are the example to run a program in bash shell or sh shell or PERL programs using  Shebang line.

#!/usr/bin/bash

#!/usr/bin/sh

#!/usr/bin/perl

If the programmer did not specify the shebang line in their program first line, then we need to run the program using the following standard. We are considering FirstProgram.sh, SecondProgram.sh and ThridPERLProgram.pl programs without shebang line. So we need to following the below method to run these programs.

$/usr/bin/bash  FirstProgram.sh

$/usr/bin/sh SecondProgram.sh

$/usr/bin/perl ThridPERLProgram.pl

Consider the suituation where we need to develop the PERL program in a Windows environment and run the same programs in UNIX environment. In this case, we need to keep the shebang line in the Windows environment, but we may installed the PERL in C:\Strawberry\perl\bin folder.

So it is difficult to keep the PERL program first line as #!C:\Strawberry\perl\bin\perl.exe and change in all files while moving into UNIX environment.

To resolve this issue, we can use hard link concept in Windows (link concept in UNIX, if you installed the PERL in a different location other than /usr/bin/perl).

Assume we have installed Strwberry PERL in C:\Strawberry\perl\bin directory structure. So to achieve /usr/bin/perl shebang line in Windows, create folder under C: as usr-> bin.

Inside the C:/usr/bin folder create a hard link .Note that this is not shortcut which we create it in our desktops and other area. Please refer the following links to know more about links concept

http://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/

How To Create Hard Link

In Windows 7:

Hard link creation in Windows 7 and Windows XP have different approach. In Windows 7, we can use fsutil or mklink commands in Windows 7. In this case, I have used fsutil to create symbolic link under C:/usr/bin folder. The sample command is given below.

C:\usr\bin>fsutil hardlink create perl “C:/Strawberry/perl/bin/perl.exe”

The FSUTIL utility requires that you have administrative privileges.

C:\usr\bin>

When we run the fsutil, we may get the “The FSUTIL utility requires that you have administrative privileges.” error message. This is because, we did not run the Command prompt as “Run As Administrator” option. So run the command prompt using “Run As Administrator” option and run the same command shown as below.

Correct procedure:

C:\usr\bin>fsutil hardlink create perl “C:/Strawberry/perl/bin/perl.exe”
Hardlink created for C:\usr\bin\perl <<===>> C:\Strawberry\perl\bin\perl.exe

C:\usr\bin>dir
Volume in drive C has no label.
Volume Serial Number is 3CDE-B3B8

Directory of C:\usr\bin

01/21/2012 08:38 PM <DIR> .
01/21/2012 08:38 PM <DIR> ..
05/15/2011 04:04 PM 14,336 perl
1 File(s) 14,336 bytes
2 Dir(s) 31,941,332,992 bytes free

C:\usr\bin>

Now, we got the “perl” executable under the C:/usr/bin folder. So using this option we can have #!/usr/bin/perl as the shebang line in Windows 7 OS also. Use the following link to know more about fsutil command.

http://technet.microsoft.com/en-us/library/cc788097(WS.10).aspx

In Windows XP:

Windows XP system don’t have the fsutil command to create hard links. So we need to use the NTFS Link software utility to create the hard links. NTFS Link utility can be downloaded from the sourceforge.net website. The website Link is given below.

http://sourceforge.net/projects/ntfslinkext/

Advertisements

Responses

  1. I used to be extremely amazed from the depth of data you selected to share below.
    Thanks for taking time to write down these types of
    an insightful and insightful piece

  2. Hi, Thank you for your kind suggestion. I try to correct the problem in my future posts.

    Thanks,
    ibmadmin

  3. obviously like your web site but you need to take a look at the spelling on several of your posts.
    Several of them are rife with spelling problems and I in finding
    it very troublesome to tell the truth however I will definitely come again again.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: