-3

I have created a OpenNotepad.bat file with text stating "C:\windows\system32" notepad.exe and saved it to my desktop. I have created a Java class. What do I have to type in the cmd to get that text from the .bat file?

Is there a specific command that I should use to get the command prompt to display that text?

Here is my Java code:

public class OpenBatchFile {
    public OpenBatchFile() {
        super();
    }

    public static void main(String[] args) {

        //Get Runtime object
        Runtime runtime = Runtime.getRuntime();
        try {
            runtime.exec("cmd /c start Desktop:\\OpenNotePad.bat");
        }
        catch (IOException e) {
            System.out.println(e);
        }
    }
}

I am totally new to this. I referred to this tutorial: Execute batch file from Java Code using Runtime class

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • If you have to read the content from batch file why are you executing the file, instead of reading the content ? – Neeraj Jain Nov 22 '17 at 08:04
  • I am totally new to this and i followed a tutorial: http://www.awasthiashish.com/2016/05/execute-batch-file-from-java-code-using.html –  Nov 22 '17 at 08:06
  • It is not clear what are you asking... are you looking for `dos` command that will display files contents (`type [filename]`) - or you want to read the contents from `java`? – PKey Nov 22 '17 at 08:07
  • I want the cmd to display the content of what is inside the OpenNotePad.bat –  Nov 22 '17 at 08:08
  • then you should use something like `type OpenNotePad.bat` – PKey Nov 22 '17 at 08:09
  • Is there any specific commands that i should use? –  Nov 22 '17 at 08:12
  • 2
    Possible duplicate of [How to display text file content in cmd?](https://stackoverflow.com/questions/17217476/how-to-display-text-file-content-in-cmd) – achAmháin Nov 22 '17 at 08:17
  • Ok the `type OpenNotePad.bat` command worked. And the command `more OpenNotePad.bat` can be used too ! Thank you so much :) –  Nov 22 '17 at 08:23
  • @Susmitha Why do you have duplicate accounts and use the one to upvote questions on the other? Each of your account questions all have upvotes. – Gerhard Nov 22 '17 at 09:54

1 Answers1

0

When in cmd.exe console, type the command help which will display all possible commands you can run in a cmd prompt or batch... If you read through each, you will notice two that stand out:

MORE           Displays output one screen at a time.
TYPE           Displays the contents of a text file.

This will display the content of any file if you use them like:

type filename.txt
more filename.txt

or

type "c:\program files\some dir\filename.txt"
more "c:\program files\some dir\filename.txt"
Gerhard
  • 22,678
  • 7
  • 27
  • 43