Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How to load a prewritten line in command prompt?

Example:


Take the followings as a line:

java -jar System.jar

Can this command line be written in a .bat file so that by clicking on the .bat file it is automatically loaded?

PS: The initial start up of the command prompt has to be

C:\Users\[USER]>

So the result would therefore be:

Line1:

C:\Users\Me> cd

Line2:

C:\Users\Me> java -jar System.jar

This would prevent one from typing a command over and over again.

share|improve this question

closed as unclear what you're asking by Ƭᴇcʜιᴇ007, nixda, Tog, Kevin Panko, Raystafarian Mar 21 at 16:00

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Yes, batch will do fine, but you maybe should be reading things about batch scripting, not asking questions yet. ;-) –  TheUser1024 Mar 18 at 16:36
    
Batch or Command script file is precisely for that. It started out as a way of not having to retype sequential sets of commands over and over again and has been extended with branch and other logic. –  Fiasco Labs Mar 18 at 16:40
    
How is it that it is actually done though because when I use echo off, it clears the C:\Users[USER]> –  Scott Mar 18 at 16:48
1  
    
A side note: you may want to check out javaw.exe. It doesn't pop up a console window. –  Rich Homolka Mar 18 at 16:54

2 Answers 2

up vote 3 down vote accepted

Batch files are really a sequence of commands that when the batch file is double-clicked or run, it runs those commands in order.

In order to create a batch file, use a program like Notepad like so

Batch File in Command Prompt

The command prompt will execute the cd command first, and then java, and after the java process closes (when your app closes), the command prompt will close automatically. If you want to not wait for the app to finish, you can do start java -jar System.jar, and that will tell the command prompt not to wait, and adding a pause at the end will tell it to wait.

Now you can save the file, by going in to the File->Save As... dialog, and after you select All Files (*.*) in the save as type and name it whatever, remembering to have the .bat extension at the end.

Save Dialog

Once we open it, we can see that the commands are ran (I added a pause at the end of mine).

Command Prompt when run

share|improve this answer

Yes, follow these steps:

  1. Open Notepad
  2. Enter the following

    cd %USERPROFILE%
    java -jar System.jar

  3. Go to File » Save As...

  4. Navigate to where you want to save the batch file.
  5. Select "All Files (*.*)" from the Save as type drop-down box.
  6. Enter WhateverYouWantToCallIt.bat in the File name text box. The important part of the filename is that it ends with .bat.
  7. Click on Save
  8. Run your batch file.

Better option: Create a shortcut

  1. Right click in the folder you want the shortcut, and click on New » Shortcut.
  2. click on the Browse button and navigate to your Java.exe path. This should be something like "C:\Program Files (x86)\Java\jre6\bin\java.exe".
  3. Click Next
  4. Type in the name of the shortcut, and click on Finish.
  5. Right click on the newly created shortcut and click on Properties.
  6. On in the Target text box, add the following to the end of the text that is already there (make sure there is space between what is there and the line below).

    -jar System.jar

    So instead of "C:\Program Files (x86)\Java\jre6\bin\java.exe" it would say

    "C:\Program Files (x86)\Java\jre6\bin\java.exe" -jar System.jar

  7. Change the text in the Start in text-box to C:\Users\Me.

  8. Optional: Click on Change Icon and browse to an .ICO file to use for your shortcut.
  9. Click on OK
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.