0

I want to open the command prompt through batch file and enter the text in the command prompt. I used the following method but it does not work.

@ECHO OFF
cls
CALL "C:\Windows\system32\cmd.exe"
cd C:\Programms\ramkumar\Java\HelloWorld
javac HelloWorld.java
java HelloWorld

But it still remains in C:\Programms\ramkumar\Java\HelloWorld and not executing the java program.

4
  • what is the error that you get? Commented Apr 1, 2014 at 4:52
  • Is java -version showing anything on cmd? Commented Apr 1, 2014 at 4:56
  • @Dale- No. Its not showing anything about version Commented Apr 1, 2014 at 5:21
  • @hellboy- Its not compiling the java program Commented Apr 1, 2014 at 5:22

1 Answer 1

1

Your batch script doesn't work the way you want it to because:

In the batch script, there is a CALL to execute cmd.exe , which essentially opens a new cmd instance on top of the current cmd instance and pauses the execution of the main script. So unless you exit the new instance created by cmd.exe, the batch file won't proceed further.

One possible solution:

Copy the last 3 lines of your batch script into a new batch file and call this new batch file from your current batch file using START or CALL.

@ECHO OFF
cls
CALL cmd /K "path_to_new_batch_file"

OR

@ECHO OFF
cls
START cmd /K "path_to_new_batch_file"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.