Windows command templates

From HaFrWiki
Jump to: navigation, search

One of the common problems developers face when developing with windows is the inflexibility to install different versions next to each other. This can be accomplished using command line scripts. An explanation how to do this is shown here.

Recommendation[edit]

Installing on your local hard disk can be fine, but more convenient is to install these scripts on a removable hard disk. So you can create portable installation, without installing anything on the host computer.

Making it work anywhere[edit]

Suppose you have a removable hard disk installed on computer 1 as drive H, on computer 1 as K:, and you are not able to change the drive-letter because the system you work on does not allow this (you are not the administrator). No problem start your scripts with

 :Begin
    pushd %~dp0
    SetLocal

The pushd %~dp0 command [1] will provide that the drive and path of the system where this file is located is selected, where ever that may be.

But do not forget to end the script with:

 :Exit
    popd

The popd command will bring you back to the original location making the script also callable from anywhere and continuing the caller at the same place.

Select JAVA Version[edit]

If you install your JAVA versions also on the same hard-disk as the command-file you can create a simple way to select a JAVA version as follows. 1. First Check is the JAVA version exist on the drive:

   if exist "<JAVA_HOME_PATH>\bin\javac.exe" (
     goto :InstallJava
   ) else (
     goto :ErrorNoJava
   )

Please note that the JAVA_HOME_PATH does not contain any drive indication. So \usr\home\java_1.6.0 is a good directory indcation.

See also[edit]

References[edit]

  1. See the full list at Windows Command Line Batch Parameter reference.