I am grabbing an update from SVN via Python.
I have this:
try:
output = subprocess.check_output(svn.update_cmd,
stderr=subprocess.STDOUT, shell=True)
print output
print 'finished svn update'
revision_number = output.split()[-1].rstrip('.') #revision number
if log_update:
write_update(revision_number)
return revision_number
except subprocess.CalledProcessError, e:
raise SVNUpdateError(e.output)
When I raise my custom SNVUpdateError, I am getting the newlines printing out as \ns.
If I try:except the SVNUpdateError, I can pretty-print the line, but it comes out as stdout, and passes on to the next block of code. I would like to raise the exception, bail out of the task altogether, and print the results from the SVN client as to why things went south without newline and other special characters.
Thanks.
Since your using Python 2.x:
That will print the message (with restricted newlines in the commented print statement) to stderr and kill the process.
EDIT
If the string has actual “\\n” characters instead of special character “\n” in the string (which means someone most likely has a type somewhere in string creation), you could do a simple string replacement before printing: