Opening CMD from Python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Opening CMD from Python (/thread-37740.html) |
Opening CMD from Python - Oshadha - Jul-16-2022 I want to open a cmd terminal at a specific directory, and run a command, then get the output to a variable in python. I searched the internet but could not find a suitable solution. Thanks... RE: Opening CMD from Python - snippsat - Jul-16-2022 Use subprocess. To make a working example open imcat in a specific folder(cwd) and catch the output. import subprocess response = subprocess.run(['imcat.exe', 'test.jpg'], capture_output=True, cwd=r'C:\cmder\bin') print(response.stdout)
RE: Opening CMD from Python - Skaperen - Jul-17-2022 you don't need a terminal to run a command, in all the common operating systems, in all the common languages. see post #2 for Python. |