Retrieving error info from a string

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Retrieving error info from a string



I have a string with this example error



File "/home/mdk/Documents/PyPad/src/New289429.py", line 1
print("SDADADFDSFDSDSFS)
^
SyntaxError: EOL while scanning string literal

Now this is the code that gives me that string:


File "/home/mdk/Documents/PyPad/src/New289429.py", line 1
print("SDADADFDSFDSDSFS)
^
SyntaxError: EOL while scanning string literal


def execute(self, command):
"""Executes a system command."""

out, err = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
self.output = out
self.error = err
return self.error



I need to strip out everything out of that string except for the SyntaxError part and the text after it. Like this: SyntaxError: EOL while scanning string literal


SyntaxError: EOL while scanning string literal



How should I do it?




2 Answers
2



Probably easiest way to do that is to grab last line from stderr:


stderr



self.errow = err.split(os.linesep)[-2]


self.errow = err.split(os.linesep)[-2]



To retrieve that part of the string


self.error = self.error.split(os.linesep)[-2]






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS