fortypoundhead.com

Search Google and Other Search Engines from the Command Prompt

Posted On 2007-04-05 by FortyPoundHead
Keywords:
Tags: General Tip Tutorial Windows XP
Views: 1553


Here''s an interesting command you can add to your Windows XP and DOS arsenal.

Just take the following text, open Notepad, and create a file google.bat in your main Windows directory (usually c:\windows):

@echo off
if not "%1"=="" (set QUERY=%1) else (goto error)
:loop
shift
if not "%1"=="" (set QUERY=%QUERY%+%1) else (goto exitloop)
goto loop
:exitloop
start http://www.google.com/search?q=%QUERY%
exit
:error
echo You did not enter a search query!

This creates a google command that starts your default web browser and uses the Google search engine to process your search query.

Examples:

google night photography help

google 2006 college basketball statistics

To search MSN''s Live.com instead, replace the "start" command with:

start http://search.live.com/results.aspx?q=%QUERY%

To search Yahoo!:

start http://search.yahoo.com/search?p=%QUERY%

To search Ask:

start http://www.ask.com/web?q=%QUERY%

Though interesting, these batch files are not perfect, as certain special characters may trip up the search.

And now, for something completely different

Why start a web browser session when you can display the results directly in the DOS prompt? Fdisk.com has a Win32/DOS port of the text-based Lynx browser.
If you download and extract the archive to c:\lynx you can replace the line of the above batch file prefixed by "start" with the following lines. This displays the top search results directly in the DOS prompt (the results may be messy, but they should be readable):

call c:\lynx\samples\lynx -nolist -dump "http://www.google.com/search?q=%QUERY%" > tmp.htm
more tmp.htm
del tmp.htm

(Note that the first two lines should actually be one line of code in the batch file.)

You may instead want to download the following batch file we have created. This batch file is an enhancement to the one written in this tip. It starts the Lynx web browser if it exists on your hard drive, and if not, your default web browser starts:

* Google search via the Windows XP / DOS command prompt


About the Author

FortyPoundHead has posted a total of 1974 articles.

 


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:54.158.252.131

Before you can post, you need to prove you are human. If you log in, this test goes away.



Recent Forum Posts

Malicious IP Checker Companion Tool
dwirch posted on August 12, 2017 at about 20:24 in Site News

Job Spammer: Steve Adams
dwirch posted on August 8, 2017 at about 7:44 in Spammers

New security implemented
dwirch posted on August 8, 2017 at about 6:43 in Site News

New security implemented
dwirch posted on July 23, 2017 at about 6:58 in Site News

Fold Code Manager into main KB?
VB6Boy posted on July 22, 2017 at about 14:42 in Site News

Fold Code Manager into main KB?
dwirch posted on July 22, 2017 at about 14:41 in Site News