-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?

2 Answers2

1

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

import subprocess
subprocess.run('powershell.exe Get-Item *')
2ps
  • 15,099
  • 2
  • 27
  • 47
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.

Matthew
  • 1,096
  • 7
  • 12