0
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?

4
  • Does this answer your question? asyncio create_subprocess_shell python 3.7 on windows Commented Dec 14, 2021 at 13:50
  • Or stackoverflow.com/questions/44633458/… Commented Dec 14, 2021 at 13:53
  • According to that link, "create_subprocess_exe" is not executed in Windows, right? Commented Dec 14, 2021 at 14:11
  • According to the link you need to use a ProactorEventLoop in order to use create_subprocess_exec in Windows (which becomes the default in Python 3.8). Commented Dec 14, 2021 at 15:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.