-2

I already know how to open windows command prompt through python, but I was wondering how if there is a way to open a windows powershellx86 window and run commands through python 3.7 on windows 10?

1

2 Answers 2

1

You can just call out to powershell.exe using subprocess.run

import subprocess
subprocess.run('powershell.exe Get-Item *')
Sign up to request clarification or add additional context in comments.

Comments

0

If you know how to run the command prompt (CMD.EXE) then you should be able to use the same method to run PowerShell (PowerShell.EXE). PowerShell.EXE is located in c:\windows\system32\windowspowershell\v1.0\ by default. To run the shell with commands use:

c:\windows\system32\windowspowershell\v1.0\PowerShell.exe -c {commands}

To launch a .ps1 script file, use

c:\windows\system32\windowspowershell\v1.0\PowerShell.exe -f Path\Script.ps1

Good luck.

Comments

Your Answer

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