Terminal values for a program

Asked

Viewed 51 times

0

I am facing the following problem by running the following commands on the terminal, java -jar logisim-filename.jar adder-test.circ -tty table i get a table on the terminal itself, delimited by tabulations, as follows:

00 00 000

01 00 001

10 00 010 etc…

In my program I need these values, only I do not know how from the terminal (which command run) pick them up and transfer to my program so that I do the necessary, if someone can tell me if you have how to do.

Editing:

My program takes a file . txt and removes this data, as if it were data from a true table, only, reading the . txt ta being made that way:

public class tt2vcd {

 public static void main(String[] args) throws IOException {


       //Leitura do arquivo gerado pelo logisim
       String fileName = args[0];           
       FileReader entrada = new FileReader(fileName);
       BufferedReader entradaFormatada = new BufferedReader(entrada);
    //Denominada uma String arquivo para manipular o nome do Arquivo do logisim
    String arquivo = fileName;

    //Trocado o tipo de arquivo, não sendo mais .txt, e sim .vcd
    arquivo = arquivo.replace("txt","vcd");

    //definida a leitura do arquivo caractere por caractere
            int c =  entradaFormatada.read();
 //realiza o processo de gravação...
}}

So what I want to do is from the terminal, get this double treatment, using a tag, so when the guy generates the truth table in the terminal, I extract the information from the terminal, and when the guy wants to use the . txt I extract from . txt.

I’m using Windows but I have access to linux too.

  • Add the code to the question.

  • What operating system do you use? I say this because, under Linux, for example, you can save the terminal output to a text file. Having this, it is easy for your program to access this file and do what you need to do.

  • If it is Linux you can do this: logisim-filename.jar Adder-test.Circ -tty table > sometext.txt This command will save a txt with terminal output, from this as Statelessdev said you can read the txt file.

  • Guys, thanks, I added the code to the question, but I think I’ll do what Statelessdev said, the program is already doing the treatment. txt in a good way, so I think it’s the way, using Windows, but I have access to Linux. Carlos Heuberger my program needs to do the treatment both by command line and by file, using a tag (for example), for differentiation. Thanks again guys

1 answer

1

Only with this information it’s hard to be 100% assertive, but come on:

To pass arguments via command line (terminal), you can pass them separated by space. Something like:

java -jar sua-app.jar 00 00 000 01 00 001

These values are received as parameters in the method main through the Strings array (in this case called args).
To read this information just iterate the array:

public static void main(String[] args) {
    for(final String arg : args) {
        System.out.println(arg);
    }
}

For Java to find its own main class you need to tell what this class is through the filing cabinet MANIFEST.MF.

  • Man, thank you so much, I added the code I’m using to the question, I haven’t tested what you said yet, I’ll test it here, thanks again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.