def run_safe(self, cmd):
if sys.platform == "win32":
cmd = 'cmd /c ' + cmd
ret_code = asyncio.run(self.coroutine_out_stream(cmd))
return ret_code
async def coroutine_out_stream(cmd):
process = await asyncio.create_subprocess_exec(*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE)
stdout, stderr = await process.communicate()
stdout = stdout.decode('utf-8')
stderr = stderr.decode('utf-8')
ret_code = process.returncode
cmd = SubProcBatch.cmd_to_string(cmd)
cmd = SubProcBatch.encrypt_password(cmd)
print('cmd :' + cmd)
print(stdout.strip())
print(stderr.strip())
print('process.returncode : ' + str(process.returncode))
return stdout, stderr, ret_code
This code works normally when the bash script is inserted into the cmd on the Mac. But in Windows batch script is not running.
Can I run a batch script using create_subprocess_exec in Windows?
Error message is "NotImplementedError". What is it?
ProactorEventLoopin order to usecreate_subprocess_execin Windows (which becomes the default in Python 3.8).