How to Run Command Line, External Program and Batch files from Eclipse Console - Tips

Hello guys, have you ever think how much time a Java developer spends on Eclipse or his favorite IDE? I guess most of his time, isn't it would be great to do as much as work possible from Eclipse itself, without switching to another application. Since switching between application or program requires some time, which is generally gone waste, I like to use Eclipse as much as possible, starting from coding in Java, executing Java program to exploring XML files, and now even running the batch command from Eclipse. Most of you know about Eclipse's external tool configuration feature, which allows you to run any external program like a batch file from local drive, but it can also be used to run command prompt from Eclipse console itself.

In this tutorial, we will learn how to run windows commands from Eclipse console, by hooking cmd.exe into Eclipse. This is a really good tip to save time and improve your speed and productivity while working for Java applications on Eclipse and Windows.

I really wish that I know about this Eclipse tip early in my career. Btw, if you are new to Eclipse you should spend some time learning the IDE you are going to use every day. If you need a recommendation, I suggest you check out the Beginners Eclipse Java IDE Training Course on Udemy. It's good and also very affordable, you can buy in just $10 on Udemy sales.

How to Run Command Prompt files from Eclipse External Tool Configuration

Here are the steps to hook command prompt to Eclipse IDE:

1) Open Eclipse External Tool Configuration as shown below:

How to run command prompt, batch files from Eclipse - Tips

2)  Create a New External Configuration

Give a name to your External Tool Configuration Setting, I usually give the name of bat file or name of the exe itself like in this case, we will call it cmd
How to Create a New External Configuration

3)  Find the batch file or external program

You can browse executable I mean,  cmd.exe from the File System. You can find in Windows/System32 folder as shown below. Once you find, just load that and Click Apply and you are done.

How to Find the batch file or external program in Eclipse

4)  Run

Now, you can click run and it will open the command prompt as shown below:

How to run the batch file or external program from Eclipse

Now, whenever you will run this external tool configuration by accessing the toolbar, you will see that command prompt open on Eclipse console. You can now execute any DOS or windows command, which is available in PATH.

Here is a snapshot of running DOS commands from Eclipse Console itself.

How to run DOS commands from Eclipse

I wouldn't say this is a very neat trick, but definitely very useful, if you happened to go back and forth to command prompt and Eclipse. This will not only save your time but also you can use Eclipse console settings to control it.

Further Learning
The Complete Java Masterclass
Eclipse Debugging Techniques And Tricks
Refactoring Java with IntelliJ IDEA

Related Java and Eclipse tutorials you may like to explore
If you like this tutorial and wants to learn more productivity tips, tricks and new features of Eclipse IDE, then you can also see the following guides and tutorials:
  • The 2020 Java Developer RoadMap (guide)
  • How to attach the source code of a JAR file in Eclipse? (steps)
  • How to debug a Java Program in Eclipse IDE? (guide)
  • How to do the static import in Java Eclipse? (solution)
  • How to escape String literal in a Java file when posted on Eclipse? (solution)
  • How to compare two files in Eclipse IDE? (guide)
  • How to increase the console buffer size in Eclipse? (solution)
  • How to make an executable JAR file in Eclipse? (steps)
  • How to solve Eclipse No Java Virtual Machine found the error? (solution)
  • How to fix the JAR dependency not working in Eclipse Maven Plugin? (answer)
  • How to fix Eclipse Not able to connect Internet or Market Place error? (solution)
  • How do you create JUnit tests in Eclipse IDE? (guide)
  • Eclipse shortcut for System.out.println() statements (shortcut)
  • How to fix an Unsupported major.minor version 51.0 error in Eclipse? (solution)
  • How to fix must override superclass method error in Eclipse? (solution)
  • How to decompile class files in Eclipse? (solution)
  • How to set java.library.path in Eclipse IDE? (steps)
  • Step by Step Guide to Remote Debug a Java Application in Linux (guide)
  • How to fix Eclipse Access Restriction error (solution)

Thanks for reading this article so far. If you like these Eclipse keyboard shortcuts, then please share this article with your friends and colleagues. If you have any questions or feedback, please drop a note.

P.S. - If you are looking for some free online courses to learn Eclipse better and improve your productivity then I suggest you check out this list of 6 Free Courses to Learn Eclipse and JUnit which not only teach you Eclipse better but also introduce you with JUnit, one of the most popular Java testing library.

No comments:

Post a Comment