0

I want to store the errors(result) of a c++ file, when it is compiled. I thought this code should store the result in the variable var

var=$(g++ file.cpp)

but when I ran this code it returned an empty variable.

Is there any way I can store the result of a c++ file compiling?

Heisenberg
  • 475
  • 8
  • 24
  • 1
    Is the output you want to store on stdout or on stderr? – Yunnosch Jun 24 '20 at 20:37
  • 2
    The search you are looking for is probably "bash capture stderr" – Ben Voigt Jun 24 '20 at 20:38
  • You might need the error stream, like 2>/dev/null, but I have no idea on how to store this as a variable. – Dominique Jun 24 '20 at 20:39
  • This is the answer https://www.configserverfirewall.com/linux-tutorials/bash-standard-error-variable/#:~:text=To%20store%20stderr%20into%20a%20variable%20we%20need%20to%20use%20command%20substitution.&text=But%2C%20by%20default%2C%20command%20substitution,stderr%20into%20the%20%24VAR%20variable. – Slava Jun 24 '20 at 20:41
  • Thanks! I'm new to both bash and c++, didn't knew that, I'll close this question. – Heisenberg Jun 24 '20 at 20:42

0 Answers0