Even if you could get this to work, your users are going to hate you for telling them there are syntax errors in their script, but not what or where they are.
So forget about subprocess and use the built-in compile function instead:
script = 'print(0'
try:
compile(script, '<string>', 'exec')
except SyntaxError as exception:
# do something user-friendly with exception...
else:
# syntax seems okay! run script...
Don't be fooled by the 'exec'
argument: this only specifies the kind of code the script contains. If there are no syntax errors, compile
returns a code object.