A cheat that routes around the impedance mismatch between
        twisted and cmd.exe with respect to escaping quotes

def _spawnAsBatch(self, processProtocol, executable, args, env,
                      path, usePTY):
        """A cheat that routes around the impedance mismatch between
        twisted and cmd.exe with respect to escaping quotes"""

        # NamedTemporaryFile differs in PY2 and PY3.
        # In PY2, it needs encoded str and its encoding cannot be specified.
        # In PY3, it needs str which is unicode and its encoding can be specified.
        if PY3:
            tf = NamedTemporaryFile(mode='w+', dir='.', suffix=".bat",
                                    delete=False, encoding=self.builder.unicode_encoding)
        else:
            tf = NamedTemporaryFile(mode='w+', dir='.', suffix=".bat",
                                    delete=False)

        # echo off hides this cheat from the log files.
        tf.write(u"@echo off\n")
        if isinstance(self.command, (string_types, bytes)):
            tf.write(bytes2NativeString(self.command, self.builder.unicode_encoding))
        else:
            tf.write(win32_batch_quote(self.command, self.builder.unicode_encoding))
        tf.close()

        argv = os.environ['COMSPEC'].split()  # allow %COMSPEC% to have args
        if '/c' not in argv:
            argv += ['/c']
        argv += [tf.name]

        def unlink_temp(result):
            os.unlink(tf.name)
            return result
        self.deferred.addBoth(unlink_temp)

        return reactor.spawnProcess(processProtocol, executable, argv, env,
                                    path, usePTY=usePTY)