【发布时间】:2018-08-31 17:26:10
【问题描述】:
我正在尝试在系统上执行代码,该代码从 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: 无效语法
【问题讨论】:
-
我不确定您要构建什么命令行字符串,但很可能您只需要在第一个
$之前删除额外的"。 -
不工作@Paxz
标签: python powershell cmd download subprocess