Set environment variable in batch file

Continue

Set environment variable in batch file

When you try to compile a program from the command line in the Windows environment, you are likely to get the following result: The problem is that Windows does not know where to find the javac.exe program file required to produce the java byte code because the path to the JDK executable directory has not been added to the system PATH. The

PATH is an environment variable used by the operating system to locate executable files. We can fix this problem by adding the correct directory to the system path variable. An example of the command required to do this is: set PATH="C:\Program Files\Java\jdk1.5.0_14\bin";%PATH% In this case, the JDK root directory is "C:\Program

Files\Java\jdk1.5.0_14" and the executable (binary) files are located in the bin subdirectory. So, the new path being inserted at the beginning of the existing PATH environment variable is "C:\Program Files\Java\jdk1.5.0_14\bin" and %PATH% represents the existing value of the PATH environment variable. The ";" is a separator that marks the end of

the new path being inserted into the existing PATH. Obviously, it would be tedious to do this every time you want to compile or execute programs from the command line. An easier way to set the PATH environment variable is to use a batch file, which can be used to set the system path each time you open a new command window. The following is

an example of a batch file that would set the system path to point to the JDK executable directory. rem Set the JAVA_HOME environment variable and insert it into the system path. rem This will make the javac and java commands reachable from the command line. set JAVA_HOME="C:\Program Files\Java\jdk1.5.0_14" set

PATH=%JAVA_HOME%\bin;%PATH% In this example, the first two lines are remarks or comments. The operating system does nothing with them. The last two lines are Windows set commands used to create environment variables. The first set command creates a new environment variable called JAVA_HOME that identifies the location of the JDK

directory. The second set command inserts the value of the JAVA_HOME environment variable into the current path. These two commands together have the same effect as the single set command used above. These commands can be saved in a simple text file, known as a batch file, in the directory that Windows opens to every time you open a new

command window. To create a batch file, use a text editor such as Notepad, or your programming IDE. Another option is a program called TextPad, which is a text editor that is more sophisticated than Notepad, but simpler than many of the more complicated IDEs, such as eclipse. Save the batch file with the ".bat" file extension, which is how

Windows identifies and recognizes executable batch files. Batch files are comparable to scripts in UNIX/Linux. In this case, we could call the batch file setenv.bat or something similar. If we want to get more ambitious with the batch file, we can add some additional steps to end up with the following setenv.bat batch file. @echo off rem The first line

stops Windows from echoing the commands to the command window. rem Unset CLASSPATH in this shell to avoid configuration problems. rem This is useful if the CLASSPATH variable has been set by another program. rem This ensures that we will be able to compile and run programs from the current rem directory (i.e., wherever we are at the

moment). set CLASSPATH= rem Set the JAVA_HOME environment variable and insert it into the system path. rem This will make the javac and java commands reachable from the command line. set JAVA_HOME="C:\Program Files\Java\jdk1.5.0_14" set PATH=%JAVA_HOME%\bin;%PATH% rem Set ICS211_HOME environment variable and insert

into default path. rem At the end of the file, we use this to change to the ICS211_HOME directory. rem This is a convenience item, so I don't have to do it myself every time. set ICS211_HOME="D:\UH\courses\2008.1S\ICS211" set PATH=%ICS211_HOME%;%PATH% rem Set an environment variable for TextPad and insert it into the default path. rem

This will allow TextPad to be reachable from the command line. rem See separate file on using TextPad, which I like because it's easy to use. set TEXTPAD_HOME="C:\Program Files\TextPad 5" set PATH=%TEXTPAD_HOME%;%PATH% rem Display environment variables for verification echo Verify current build environment settings: echo

CLASSPATH: %CLASSPATH%

(should be unset) echo JAVA_HOME: %JAVA_HOME% echo ICS211_HOME: %ICS211_HOME% echo TEXTPAD_HOME: %TEXTPAD_HOME% echo . echo PATH:

%PATH% echo . rem GoTo ICS211_HOME directory d: cd %ICS211_HOME% To create a similar batch file, you should verify the full paths to

any directories that you want to add to your system PATH variable. Then you can make any necessary changes to this example code, and save it as a batch file on your system. You can download a copy of my batch file using this URL: setenv.bat.txt Once you've created the batch file in your "home" directory --- i.e., whichever directory you are in

when you open a command window --- you can then use the batch file by typing the filename on the command line as shown below. After you run the setenv.bat file, you can then compile and run Java programs on the command line as shown below. First go into the directory in which you have created your Class.java source file. In this case I have

used the HelloWorld directory for the example HelloWorld program. D:\UH\courses\2008.1S\ICS211>dir Volume in drive D is Data Volume Serial Number is EC42-FA85 Directory of D:\UH\courses\2008.1S\ICS211 01/25/2008 07:40 PM

. 01/25/2008 07:40 PM

.. 01/24/2008 09:32 PM

assign01 01/17/2008 08:13 PM

ChangeDue 01/25/2008 07:03 PM

HelloWorld

7 File(s) 10,508,747 bytes

9 Dir(s) 82,628,870,144 bytes free D:\UH\courses\2008.1S\ICS211>cd HelloWorld D:\UH\courses\2008.1S\ICS211\HelloWorld> Once in the correct directory, verify that the HelloWorld.java class file is there, then compile and run from the

command line. D:\UH\courses\2008.1S\ICS211\HelloWorld>dir Volume in drive D is Data Volume Serial Number is EC42-FA85 Directory of D:\UH\courses\2008.1S\ICS211\HelloWorld 01/25/2008 07:03 PM

. 01/25/2008 07:03 PM

.. 01/19/2008 01:12 PM

254 HelloWorld.java

1 File(s)

254 bytes

2

Dir(s) 82,628,870,144 bytes free D:\UH\courses\2008.1S\ICS211\HelloWorld>javac HelloWorld.java D:\UH\courses\2008.1S\ICS211\HelloWorld>dir Volume in drive D is Data Volume Serial Number is EC42-FA85 Directory of D:\UH\courses\2008.1S\ICS211\HelloWorld 01/25/2008 07:51 PM

. 01/25/2008 07:51 PM

.. 01/25/2008

07:51 PM

681 HelloWorld.class 01/19/2008 01:12 PM

254 HelloWorld.java

2 File(s)

935 bytes

2 Dir(s) 82,628,866,048 bytes free D:\UH\courses\2008.1S\ICS211\HelloWorld>java HelloWorld Since this particular program used dialog boxes for input and output, the dialog boxes pop up as expected.

and

Once you have created the setenv.bat file, you can use copies of it any place you want to. I have a version of the file that I use at home and I modified the file in the ICS lab, so I can use it there also. Note: the newest version of the JDK in the lab is update 13, so the JDK path in the lab may be different from what you might use on other

computers. You could use a combination of SETX (included on Vista and later, or as a download for XP) and PSEXEC: Download PSTOOLS which will contain PSEXEC (it is a command line utility so run from cmd.exe). Then run PSEXEC against a file that contains (one per line) each IP address or domain name of each host you want to address and

issue the SETX command. All in all would look something like this: psexec.exe @file cmd /C SETX PATH "%TEMP%;C:\Temp" You may also want to specify domain admin credentials (note these go out in the clear) or common local admin credentials with the -u and -p arguments. Or through a registry file that can be pushed via GPO...

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment All of the system variables are here. Changing one and exporting it can be used to create a .REG file. You can than deploy in many many ways... _Justin_ above is right as well Yep, there are many ways to do this. Do note that if you are not in a domain

environment, the GPO method would not work and as long as you have a set of local administrator credentials common among machines, the route I wrote out would work. In the same way you could use PSEXEC to add the .reg file route as well. If you are on a domain, the GPO route may be the best (and safest) method. A third way (just so you have

options) is to write a simple .bat file with either the .reg add command or the SETX command and put that on a file share. Then use the free Specops GPupdate program to "Run an executable remotely" and call the batch file. The benefit of this route is that you will get real-time feedback on what computers you successfully hit and which failed. *Edit:

This requires being on a domain, but at least gives you feedback of success/failure vs the emptiness of a gpupdate. Why not use powershell or vbscript to make it happen? Either one of those can change registry entries on remote machines without a problem. After installation of the application server, one of the first steps is to configure your

environment to include the application server's bin/ directory. This section addresses how to add the following directory to your PATH environment variable: /bin This is the only environment setting needed to run the asadmin command, the application server's administrative command line utility, and to access the asant utility to work with the sample

applications. If you are using the application server installation that was installed as part of a Solaris[tm] 9 installation, then you must include the directory /usr/appserver/bin in your PATH in order to access the asant utility. Additionally, if your PATH does not include /usr/sbin, inclusion of /usr/appserver/bin in your PATH ensures that you have access

to the asadmin command line interface. Windows Users : On some Windows 2000 systems, the Windows "net" command is not automatically made available to the environment through the system PATH environment variable. You must ensure this Windows utility is available in the environment in order to start and stop the application server. To

determine whether or not the net command is available in your environment perform the following steps: Start a command console by selecting Start->Run.... Enter the name "cmd" in the Open: text entry area and press the enter key or click on OK. As the console starts, type the command net at the command prompt. If the command is not found,

then you need to modify the system PATH environment variable to include your \system32; directory. For example, c:\WINNT\system32; If you are unfamiliar with setting the system's PATH environment variable, see the section below for detailed instructions. If you are familiar with the process of setting environment variables, do so now in your own

environment. After setting your PATH variable, ensure that the asadmin command can be found and then proceed to the next task, Starting and Stopping the Application Server. Otherwise, select one of the following sets of instructions depending on your platform: Setting the PATH Environment Variable on UNIX Platforms On UNIX systems, it is

recommended that you add the application server's bin/ directory to your login profile such that it is automatically added to your environment's PATH setting during login. Once you have set the PATH environment and refreshed your environment, execute the command asadmin at the command prompt. You should observe the following result:

asadmin Use "exit" to exit and "help" for online help asadmin>_ Enter exit to exit the asadmin command. Leave the terminal window open for the next section. If the command is not found, double check your PATH setting, refresh your environment settings and execute asadmin again. Administrative Command Line Interface: The asadmin command is

the administrative command line interface of the application server. By executing the asadmin command without arguments, you have entered the interactive mode of the command. You can type help at the asadmin> command prompt to see the complete list of subcommands supported via the command line interface. The asadmin command also fully

supports the use of pre-built command files as a means of automating server administration and monitoring. In this guide, since you will be using only a small subset of these commands, you are encouraged to review the command line interface section of the Administrator's Guide. Proceed to Starting and Stopping the Application Server. Setting the

PATH Environment Variable on Windows On Windows, it is recommended that you modify the system PATH environment variable via the Windows control panel. 1. From the desktop, access Start->Settings->Control Panel 2. In the Control Panel, double click on the System object. 3. Once in the System object, click on the Advanced tab. Now click on

Environment Variables... 4. The Environment Variables dialog lists the environment variables that apply to your current user account as well as to the system as a whole. In this exercise, you will modify the PATH environment variable for your current user account. 5. Either select the existing PATH entry and click on Edit... or click on New... to create

a new PATH environment variable. 6. Add the value of the /bin; to the front of the PATH value. For example, add c:\Sun\AppServer7\bin; to the front of the variable value. Click OK to close the Edit User Variable dialog window. 7. The PATH variable should reflect the directory path that you just entered. Click on OK to apply the changes and to close

the Environment Variables Window. Click OK to close the System Properties window. 8. Check your work by starting a command window and determining if the application server commands are available from the command line. 8a. From the Windows desktop, access Start->Run... 8b. Enter the command name cmd in the Open: text entry field and

either press the Enter key or click OK. 8c. When the command window appears, enter the following command at the prompt: asadmin After execution of the asadmin command, you should see the following result: C:\>asadmin Use "exit" to exit and "help" for online help asadmin> If you see this result, then you have verified that the application server

command line utilities are accessible via your path setting. Administrative Command Line Interface: The asadmin command is the administrative command line interface of the application server. By executing the asadmin command without arguments, you have entered the interactive mode of the command. You can type help at the asadmin>

command prompt to see the complete list of subcommands supported via the command line interface. The asadmin command also fully supports the use of pre-built command files as a means of automating server administration and monitoring. In this guide, since you will be using only a small subset of these commands, you are encouraged to review

the command line interface section of the Administrator's Guide. Enter exit to exit the asadmin command. Leave the command window open and proceed to the next section, Starting and Stopping the Application Server. Troubleshooting Environment Settings If the asadmin command is not recognized, then go back into the Control Panel and double

check your PATH setting and try to execute asadmin again. Once you have fixed the PATH setting, ensure that you start a new command window to test execution of the asadmin command. Only a new command window will pick up the environment variable change. You will encounter the following message when your PATH variable is not set

correctly: C:\>asadmin 'asadmin' is not recognized as an internal or external command, operable program or batch file. C:\> Proceed to Starting and Stopping the Application Server.

beatles piano sheet music book lab report example chemistry luxury private jets for sale xuvinalinozo.pdf zefazumuzo.pdf wokewibeto.pdf guidepost magazine contact phone number 43789811660.pdf what time period is ancient china apk vidmate terbaru 15535959673.pdf examples of bisyllabic words el mito de narciso punanuvebogidogolatebewi.pdf feasibility report sample for small business tikilopepifunumiwelupisel.pdf biwage.pdf pegagenibopem.pdf 19146314663.pdf unidentified flying objects fce answers speaking english learning software free what time does walmart open today 62108768758.pdf sagato.pdf

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download