Running Curl and Grep on Windows

0

I'm trying to run the following command in windows. I've managed to install cURL, but Grep still fails to identify as a command.

curl -k --silent "http://192.168.1.135:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=USERNAME&pwd=PASSWORD" | grep -oP "(?<=motionDetectAlarm>).*?(?=</motionDetectAlarm>)"

Is there an alternative command or a way to install Grep onto Windows?

Update I've installed Grep and added the following to my Path variables, both system and user, and restarted to no avail. C:\Program Files (x86)\GnuWin32

Lukas

Posted 2018-03-21T16:02:44.063

Reputation: 151

Have you installed grep? If so, make sure it is in your path. If you haven't installed it then go to Grep for Windows

– DavidPostill – 2018-03-21T16:28:48.390

I used the installer from the site and left it to the default location (Program Files (x86)). Should I install in to the path (Windows/System32)? – Lukas – 2018-03-21T16:33:15.060

Add the location to your path. See What are PATH and other environment variables, and how can I set or use them?

– DavidPostill – 2018-03-21T16:41:30.337

I've done so yet I still receive the same error. – Lukas – 2018-03-21T17:00:36.953

Did you start a new cmd shell after changing the path? – DavidPostill – 2018-03-21T17:19:34.557

Yeah and it still provided that error even after a restart – Lukas – 2018-03-21T17:23:16.607

Please [edit] the question to include your complete path and the exact error message. – DavidPostill – 2018-03-21T17:25:26.187

1run echo %PATH% and do dir grep.exe /s/b by the way, the file should probably be in gnuwin32\bin not in just gnuwin32. And gnuwin32\bin should be in the path – barlop – 2018-03-21T17:47:39.720

anyhow gnuwin32's grep is probably old.. cygwin's is from 2017 c:\cygwin\bin\grep.exe --version grep (GNU grep) 3.0 (When I last saw gnuwin32's grep it was quite a lot older, you can use it but it has some bugs and the later one is probably better anyway, and cygwin has the latest one). But worth getting the gnuwin32 one working so you know how to do that as that is good knowledge for getting any command working. – barlop – 2018-03-21T17:49:14.777

Answers

0

I've installed Grep and added the following to my Path variables, both system and user, and restarted to no avail.

A couple things to remember:

  • As @barlop comments, the path should be e.g. C:\Program Files (x86)\GnuWin32\bin.

  • It is perfectly fine to specify the whole path to grep e.g.:

    curl -k --silent "http://192.168.1.135:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=USERNAME&pwd=PASSWORD" | "C:\Program Files (x86)\GnuWin32\bin\grep.exe" -oP "(?<=motionDetectAlarm>).*?(?=</motionDetectAlarm>)"

Anaksunaman

Posted 2018-03-21T16:02:44.063

Reputation: 9 278