0

I would like to create a batch file that once you type something in and click enter you go to an search page on the Internet. The thing is, you type in a keyword before what you want to search. So say I wanted to search the mass of a whale or something, into my program I would type "search what is the mass of a whale" so to tell if I want to go on the Internet or not the script reads to see if the word search is in front of the question. If it is, it searches the Internet, if it isn't my program displays "Retype the command" or something. Any help would be great thanks

Billy
  • 11
  • 1
  • 3
  • I would say http://curl.haxx.se – Anyone_ph May 09 '15 at 04:21
  • possible duplicate of [Batch, Can I open a url from a batch script?](http://stackoverflow.com/questions/30142502/batch-can-i-open-a-url-from-a-batch-script) – 0m3r May 09 '15 at 17:34

1 Answers1

0

You can do this with a one-liner. Save this as search.bat:

@start "" "http://www.google.com/search?q=%*"

Then in a console window, run the command:

search What is the airspeed velocity of an unladen swallow?
rojo
  • 24,000
  • 5
  • 55
  • 101
  • Can you explain to me how this works? I think I'm doing something wrong – Billy May 09 '15 at 16:22
  • The `start` command launches the default handler for `http://` -- Internet Explorer or Firefox or whatever is your default web browser. `search` is shorthand for `search.bat`, with argument 1 as `What`, arg 2 as `is`, and so on... and `%*` as all arguments. All this is doing is building a URL of `http://www.google.com/search?q=What is the airspeed etc.`, then launching the default handler for that address. – rojo May 09 '15 at 21:19
  • For some reason when I type 'start www.google.com' it says application missing any way someone can tell me what's going on – Billy May 09 '15 at 22:27
  • I wonder whether you installed Google Chrome and set it as the default browser, then uninstalled it? Apparently your system's default for URL handlers is broken. You should go to your Start menu --> Control Panel, switch to Classic View if you haven't already, and go to Default Programs to fix it. If that doesn't help, then this would be a better question for [Super User](http://superuser.com/), as Stack Overflow is intended more for coding than for desktop support. – rojo May 10 '15 at 01:03