从批处理文件搜索Google [英] Searching google from a batch file

查看:63
本文介绍了从批处理文件搜索Google的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,为简单起见,我创建了一个批处理文件,该文件将充当快捷菜单以减少桌面空间.我也添加了一些额外的功能.这些功能之一是搜索Google的功能.我查找了与此相关的其他主题,并将更改空间更改为"+".在我输入通过键入BACK返回主菜单的选项之前,此方法相当不错.该功能有效,但我无法再搜索多个术语.另外,我的许多搜索都将我带到了Google主页.有什么想法吗?

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

推荐答案

请注意此 if 比较中的引号,以防止空格和其他字符.

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

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

您可以在下面使用此代码,并且当按下 enter 时, if 会分支,否则将执行搜索,并且 SC + 替换变量将在没有单独一行的情况下发生.

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

这篇关于从批处理文件搜索Google的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆