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 Carlos 20.07.2016 в 17:45
source

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.

    
answered by 20.07.2016 / 18:11
source
6

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

answered by 21.07.2016 в 10:55