title: Node.js child_process spawnSync catch errors from python script
body: <p>I am using child_process spawnSync method to run some python scripts, its all working but im unable so far to catch the errors thrown by python in try/catch blocks and it would be good if i also could catch errors raised manually from python.</p>
  
  <p><strong>Example:</strong></p>
  
  <p><strong>Node.js</strong></p>
  
  <pre><code>try {
          const process =
            await spawn('python3', [ Helpers.resourcesPath('pythonScripts/main.py'),
              debug_mode,
              lang
            ], { input: '"' + front_img + '""' + back_img + '"' });
  
          const errorText = process.stderr.toString().trim();
  
          if (errorText) {
              return response.badRequest({
                  message: errorText
              });
          } else {
              return response.success({
                  message: process.stdout.toString().trim()
              });
          }
      } catch(e) {
          return response.badRequest()
      }
  </code></pre>
  
  <p><strong>Python</strong></p>
  
  <pre><code>try:
  
      ocr = tool.image_to_string(Image.fromarray(img))
  
      for key, words in languages.items():
  
          result = [x.strip() for x in words.split(',')]
  
          if any(x in ocr for x in result):
              languageDetected = key
  
              if languageDetected: break
  
      if languageDetected:
          return languageDetected
      else:
          # I want also to be able to get this as a error in node.js
          raise Exception('Language not detected')
          sys.exit(1)
  
  except Exception as e:
      print(str(e))
      sys.exit()
  </code></pre>
  
  <p>In this example, if in the python code a error is caught in the catch(e) it will return it to process.stdout instead process.stderr, i want to be able to check if its either a error was returned or a good response in node.js.</p>
  
  <p>It would be good if i could also caught this exception throwed manually in node.js</p>
  
  <pre><code>raise Exception('Language not detected')
  </code></pre>