Question

So, to make things simple, I created a batch file that will act as a shortcut menu to reduce space on my desktop. I've added a few extra features too. One of these features is a function that searches Google. I looked up some other topics that have to do with this, and got this change spaces into "+". This worked decently fine until I put the option to go back to the main menu by typing BACK. that function works, but I can no longer search multiple terms. Also, many of my searches bring me to the Google homepage instead. Any ideas?

Here is the portion of the script having to do with this. there IS another tab called menu.

:search
echo.
echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo Google Search
echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo.
echo Please type search word or phrase and press ENTER
echo To return to the menu, type BACK in all caps.
echo.
set /p SC=Search Criteria: 
if %SC%==BACK goto menu 
if %SC% NEQ BACK (set string=%SC: =+%) & (start "" /b "C:\Program Files\InternetExplorer\iexplore.exe" "http://www.google.com/search?q=%string%")
pause 
echo.
echo ------------------------------------------------------
echo Where to?
echo ------------------------------------------------------
echo.
echo 1 - Search again
echo 2 - Main Menu
echo.
echo 3 - EXIT
echo.
set /p m=Type 1, 2, or 3 then press ENTER: 
if %m%==1 goto search
if %m%==2 goto menu
if %m%==3 goto close

No correct solution

OTHER TIPS

Note the quotes in this if compare which protects against spaces and other characters.

if /i "%SC%"=="BACK" goto Menu

You can use this code below and the if will branch when enter alone is pressed, otherwise the search will be performed, and the SC variable replace with + will happen without a separate line.

set "sc="
set /p "SC=Search Criteria: "
if not defined SC goto menu 
start "" /b "C:\Program Files\InternetExplorer\iexplore.exe" "http://www.google.com/search?q=%SC: =+%"
pause

You need to URLEncode the search string. simply invoke a java program that takes arguments from batch. Java URLEncodes your search entry and invokes browser. Should work I believe.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top