How to read the command line?

6

Let's say I want to do a routine to automate the process of compiling a program. In general (regardless of language), you call the compiler from the command line. For example:

  

javac myProgram.class

or

  

gcc myProgram.c -o myProgram

On Windows, we can use system() . But how to read the command line? In the case of a compiler, for example, how to read the possible errors returned by the compiler on the command line. In other words, how do IDEs do this? This would be important if we wanted to integrate any program with a CLI interface to our system, not just for compilers.

    
asked by anonymous 20.07.2016 / 17:45

2 answers

2

It is best to put the two processes (your two programs) to talk to each other. It can be in many different ways, for example: file, shared memory, messages or socket.

As you mentioned Windows console, a possible solution in this case is to redirect the console output to a file and then print it to the console.

Your system call would look more or less like this:

gcc meuPrograma.c -o meuPrograma > arquivo.txt | type arquivo.txt

So your next program could read this .txt file as well.

    
20.07.2016 / 18:11
6

Do you want to get the result of system() within your program? Use POSIX popen() or #

21.07.2016 / 10:55