我正在尝试在系统上执行代码,该代码从Windows上的%appdata%
目录直接链接下载文件。
我的代码:
def downloadfile():
mycommand = "powershell -command "$cli = New-Object System.Net.WebClient;$cli.Headers['User-Agent'] = {};$cli.DownloadFile('https://drive.google.com/uc?export=download&id=19LJ6Otr9p_stY5MLeEfRnA-jD8xXvK3m', '%appdata%\putty.exe')""
down = subprocess.call(mycommand)
downloadfile()
但我得到这个错误:
文件“searchmailfolder.py”,第4行mycommand =“powershell -command”$ cli = New-Object System.Net.WebClient; $ cli.Headers ['User-Agent'] ='myUserAgentString'; $ cli.DownloadFile(' https://drive.google.com/uc?export=download&id=19LJ6Otr9p_stY5MLeEfRnA-jD8xXvK3m','%appdata%\ putty.exe')“”^ SyntaxError:语法无效
希望这会有所帮助。导入子进程和sys。然后尝试类似“command = subprocess.Popen([”powershell.exe“,”user_command.ps1“],stdout = sys.stdout)command.communicate()”尝试将代码放入.ps1文件