I'm calling a command line program in python using the os.system(command)
call.
How can I call this command passing a different folder for execution? There is a system call for this? Or I should save the current folder, and, after execution, change restore it.
What to Know. Type cmd into the search bar to open the command prompt. Shift + right click in a window, then click Open PowerShell Window here to access the PowerShell interface. Open the folder you wish to access, then type cmd into the folder path at the top of the window to open a command prompt within the folder.
Here are the different ways to change your CMD directory in Windows 10 or Windows 11: Open the Command prompt, type in cdcdThe cd command, also known as chdir (change directory), is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files.https://en.wikipedia.org › wiki › Cd_(command)Cd (command) - Wikipedia followed by the directory you want to move into, and hit Enter. Change the Windows directory by entering the drive name followed by : in the Command prompt, and hit Enter.
For instance, if you wanted to change the drive from C: to D:, you should type: d: … and then press Enter on your keyboard. To change the drive and the directory at the same time, use the cd command, followed by the /d switch.
If you want to open elevated Command Prompt, you should press Ctrl + Shift + Enter. After the Command Prompt opens, you can type the drive letter of the desired drive, followed by a colon, e.g. C:, D:, and hit Enter. The CMD.exe will change to the drive letter of the target drive.
The subprocess
module is a very good solution.
import subprocess p = subprocess.Popen([command, argument1,...], cwd=working_directory) p.wait()
It has also arguments for modifying environment variables, redirecting input/output to the calling program, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With