I have not been able to find an answer in google or other places, I hope you can guide me.
I have a node.js
app that calls an executable (.exe)
file that sometimes fails, My code is the following:
const converter = childProcess.spawn('converter.exe', [source, destination], options);
converter.stdout.on('data', (data) => {
});
converter.on('close', (code) => {
console.log(`Child process exited with code ${code}`);
});
converter.stderr.on('data', (data) => {
});
Everything works well, but when I get an stderr I don't know how to get the message, I logged the data and I got this:
stderr:
I can get a string using .toString(), the string is the following:
stderr: Traceback (most recent call last):
File "converter.pyw", line 23, in <module>
doc = word.Documents.Open(source_file)
_ctypes.COMError: (-2146822496, None, ('El archivo parece estar corrompido.', 'Microsoft Word', 'wdmain11.chm', 25272, None))
My doubt now is, is it possible to extract the error message only? In this case the error message is El archivo parece estar corrompido.
I even tried using JSON object to parse it but i've got no luck.
Edit:
As I control the generation of the .exe
file I will try using some try except code blocks (yes it's python code), but I don't know If I will still get text like sterr: Traceback... I'll edit this question as soon as I get my results.
As I was expecting from the beginning there is no built in method to extract the errors I get from my exe file, the error is a string that could be worked out to get the error message but that could be complex.
I tried using try except block in my python code that later is compiled into the exe file, it looks something like:
try:
except:
sys.stderr.write('Error')
Now, the output in my error handling function is:
Error
I guess the answer in the end is to control the output that comes out of the childprocess file.