Jul-16-2022, 02:54 AM
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...
Thanks...
Opening CMD from Python
|
Jul-16-2022, 02:54 AM
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...
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)
Jul-17-2022, 11:22 PM
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.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American. |
|