У меня работает CmdLet PS:
New-Item -ItemType SymbolicLink -Path "C:\Users\user1\Saved Games\Scripts\BIOS" -Target "C:\Users\user1\Saved Games\bios\Scripts\BIOS"
Мне нужно запустить от имени администратора (конечно), поэтому оберните Start-Process и перейдите к подпроцессу Python
Я думаю, это может быть что-то вроде:
def run_cmd(*args):
p = subprocess.Popen(*args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, error = p.communicate()
return out, error
cmd_symlink = '"New-Item -ItemType SymbolicLink -Path "C:\Users\user1\Saved Games\Scripts\BIOS" -Target "C:\Users\user1\Saved Games\bios\Scripts\BIOS"'
ps_command = f"& {{Start-Process powershell.exe -argumentlist '-command {cmd_symlink}' -Verb RunAs}}"
command = ['powershell.exe', '-command', ps_command]
run_cmd(command)
или????
Решение:
cmd_symlink = r'"New-Item -ItemType SymbolicLink -Path \"C:\Users\user1\Saved Games\Scripts\BIOS\" -Target \"C:\Users\user1\Saved Games\bios\Scripts\BIOS\"'
ps_command = f"Start-Process pwsh.exe -argumentlist '-command {cmd_symlink}' -Verb RunAs"
command = ['pwsh.exe', '-command', ps_command]
run_cmd(command)
Подробнее здесь: https://stackoverflow.com/questions/790 ... subprocess