0

I am trying to compile and run a C++ file using execSync(). It works fine when there are no compilation errors. But when a compile time error occurs the output returned by execSync() is an empty buffer. How do I get the error message ?

This is my code:

this is how my code looks like

This is the returned output that I'm trying to capture:

this is what i want as my returned output

Rup
  • 33,765
  • 9
  • 83
  • 112
  • I don't know execSync but I'd guess the problem is you're fetching back the stdout output whereas the compiler is reporting errors to stderr. – Rup Jul 09 '18 at 11:22
  • Maybe this answer helps you: https://stackoverflow.com/a/43077917/6942210 – Philipp Kief Jul 09 '18 at 13:36
  • @PhilippKief try catch was not working for me , may be because the child process has done its job perfectly by running the command, exception only occurs either when process times out or has a non-zero exit code. Actually the problem is solved , i just used spawnSync() and accessed the stderr stream. – Gaurav Bisht Jul 09 '18 at 15:26

0 Answers0