我正在运行PowerShell脚本,如下所示:
$url = "http://api.weatherunlocked.com/api/forecast/29.36,47.97?app_id=****&app_key=****";
$req = [System.Net.WebRequest]::Create($url)
$req.Method ="GET"
$req.ContentLength = 0
$req.Timeout = 600000
$resp = $req.GetResponse()
$reader = new-object System.IO.StreamReader($resp.GetResponseStream())
$reader.ReadToEnd() | Out-File weatherOutput.json
它发出以下错误:
run.sh: line 2: syntax error near unexpected token `('
run.sh: line 2: `$req = [System.Net.WebRequest]::Create($url)'
答案 0 :(得分:3)
考虑到错误始于run.sh
,您似乎正在尝试在UNIX中运行PowerShell脚本。 Powershell代码只能在安装了PowerShell的Windows机器上运行(内置于Win7 +,单独安装xp和vista)。
尝试在Windows机器上使用此命令运行脚本:
PowerShell.exe -ExecutionPolicy Bypass -File "C:\myscript.ps1"
答案 1 :(得分:0)