我正在尝试在系统上执行代码,该代码将从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 =新对象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:语法无效
答案 0 :(得分:0)
希望这会有所帮助。导入子进程和sys。然后尝试这样的事情 “命令= subprocess.Popen([”“ powershell.exe”,“ user_command.ps1”],stdout = sys.stdout) command.communicate()” 尝试将代码放入.ps1文件