Reputation: 3
I am running a PowerShell script as follows:
$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
It's giving the following error:
run.sh: line 2: syntax error near unexpected token `('
run.sh: line 2: `$req = [System.Net.WebRequest]::Create($url)'
Upvotes: 0
Views: 997
Reputation: 200473
In a Unix environment use wget
or curl
.
url="http://api.weatherunlocked.com/api/forecast/29.36,47.97?app_id=****&app_key=****"
wget -O weatherOutput.json $url
If you want the data echoed to STDOUT
just replace the filename with -
. You may also want to add the parameter -q
to suppress informational/progress output.
wget -qO - $url
Or use curl
, which writes the data to STDOUT
by default.
Upvotes: 0
Reputation: 54971
It looks like you're trying to run a PowerShell script in UNIX considering the error starts with run.sh
. Powershell code can only be run on Windows machines With PowerShell installed (built in from Win7+, separate install for xp and vista).
Try running your script like using this command on a Windows-machine:
PowerShell.exe -ExecutionPolicy Bypass -File "C:\myscript.ps1"
Upvotes: 3