How do I run cmd in Python code so that it is automatically entered?

Asked 2 years ago, Updated 2 years ago, 150 views

Hello, I have a question.

To run the program now, turn on the virtual environment in cmd, go to the appropriate folder path, and then python run.The program runs only when you run py.

We found the os module and subprocess module while looking for commands that can be used to virtualize, file paths, and execute, such as typing this directly into cmd within the Python code.

This was different from the direction I thought was using the result executed in the shell.

Is there any way to run cmd with Python command so that it is automatically entered here?

Or is there any other way?

Thank you for your reply.

python cmd py

2022-09-20 21:40

1 Answers

After determining the Python location of the virtual environment,

d:\envs\envtf\script\python.exe d:\dev\myproj\src\run.py

I think this is the easiest way to do it.


2022-09-20 21:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.