How to execute a google/yahoo/duckduck search from command line, or Harbour?
Moderator: Rathinagiri
-
- Posts: 197
- Joined: Thu Jul 16, 2020 5:42 pm
- DBs Used: DBF
How to execute a google/yahoo/duckduck search from command line, or Harbour?
Hi,
I tried running command lines like
"C:\Program Files\Google\Chrome\Application\chrome.exe" /search?q=what+the
, and similar. But nothing does the trick, so far.
Is there a way to execute search engines with parameters, from inside Harbour/Minigui?
Note: I'll translate the MiniGui.chm file into other formats over the weekend. Been crazy busy with office & personal items.
I tried running command lines like
"C:\Program Files\Google\Chrome\Application\chrome.exe" /search?q=what+the
, and similar. But nothing does the trick, so far.
Is there a way to execute search engines with parameters, from inside Harbour/Minigui?
Note: I'll translate the MiniGui.chm file into other formats over the weekend. Been crazy busy with office & personal items.
- serge_girard
- Posts: 3312
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?
Hi!
You will have to start google too...!
c:\Progra~1\Google\Chrome\Application\chrome.exe www.google.com/search?q=what+the
Serge
You will have to start google too...!
c:\Progra~1\Google\Chrome\Application\chrome.exe www.google.com/search?q=what+the
Serge
There's nothing you can do that can't be done...
-
- Posts: 197
- Joined: Thu Jul 16, 2020 5:42 pm
- DBs Used: DBF
Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?
Yes. of course. Thanks, Serge.
serge_girard wrote: ↑Tue Aug 30, 2022 3:49 pm Hi!
You will have to start google too...!
c:\Progra~1\Google\Chrome\Application\chrome.exe www.google.com/search?q=what+the
Serge
-
- Posts: 197
- Joined: Thu Jul 16, 2020 5:42 pm
- DBs Used: DBF
Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?
Looks like there's a problem executing HB_Run with parameters. If we just execute
App_s := "C:\Program Files\Google\Chrome\Application\chrome.exe"
HB_Run( Chr(34) + App_s + Chr(34) )
, it runs fine.
But when we add parameters, even if we surround them with Chr(34), harbour stops interpreting the application path with spaces:
App_s := "C:\Program Files\Google\Chrome\Application\chrome.exe" + " www.google.com" (skipping the search term here, for simplicity)
or
App_s := "C:\Program Files\Google\Chrome\Application\chrome.exe www.google.com" (skipping the search term here, for simplicity)
HB_Run( Chr(34) + App_s + Chr(34) )
'Unknown command "c:\Program"'
App_s := "C:\Program Files\Google\Chrome\Application\chrome.exe"
HB_Run( Chr(34) + App_s + Chr(34) )
, it runs fine.
But when we add parameters, even if we surround them with Chr(34), harbour stops interpreting the application path with spaces:
App_s := "C:\Program Files\Google\Chrome\Application\chrome.exe" + " www.google.com" (skipping the search term here, for simplicity)
or
App_s := "C:\Program Files\Google\Chrome\Application\chrome.exe www.google.com" (skipping the search term here, for simplicity)
HB_Run( Chr(34) + App_s + Chr(34) )
'Unknown command "c:\Program"'
Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?
Hi Automator,
Maybe the example below can help you.
I create a temporary html file that is launched with the 'execute file' commando.
Advantage, your default browser is opened.
Regards
Hans
Maybe the example below can help you.
I create a temporary html file that is launched with the 'execute file' commando.
Advantage, your default browser is opened.
Regards
Hans
Code: Select all
#include <hmg.ch>
FUNCTION Main
// form
DEFINE WINDOW form1 ;
row 200 ;
col 500 ;
clientarea 500, 250 ;
TITLE 'GRID DEMO' ;
WINDOWTYPE MAIN ;
NOSIZE
// start search
Define Button bt_search
Row 20
Col 20
width 175
Caption 'Search'
Action google()
End Button
// search
define TEXTBOX tb_text
row 60
col 20
height 23
width 350
VALUE "hmg forum"
end textbox
ON KEY ESCAPE ACTION ThisWindow.Release
end window
// activate window
ACTIVATE WINDOW form1
return nil
// open browser and search
function google()
local cHtml := ""
local fn_html := "search.html"
cHtml += '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
cHtml += '<html>'
cHtml += '<head>'
cHtml += ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
cHtml += ' <title>Hmg Google search</title>'
cHtml += '</head>'
cHtml += '<body>'
// insert search string
cHtml += '<meta http-equiv="refresh" content="0; url=http://google.com/search?q='+ strtran(getproperty("form1","tb_text","Value"),' ','+') + '">'
cHtml += '</body>'
cHtml += '</html>'
// write modified model to a temp. file
hb_memowrit( fn_html, cHtml)
// execute this html file, windows OS opens iexplorer or chrome or
// whatever in function of file extension association defined in windows.
execute file (fn_html)
return nil
-
- Posts: 197
- Joined: Thu Jul 16, 2020 5:42 pm
- DBs Used: DBF
Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?
Thanks hans,
But I don't this will work, on this instance. I'm not sure where EXECUTE FILE is defined, because it's not in any of the minigui .CH files.
At at rate, this is a Windows example. My application is text mode.
But I don't this will work, on this instance. I'm not sure where EXECUTE FILE is defined, because it's not in any of the minigui .CH files.
At at rate, this is a Windows example. My application is text mode.
hansmarc wrote: ↑Tue Aug 30, 2022 7:30 pm Hi Automator,
Maybe the example below can help you.
I create a temporary html file that is launched with the 'execute file' commando.
Advantage, your default browser is opened.
Regards
Hans
Code: Select all
#include <hmg.ch> FUNCTION Main // form DEFINE WINDOW form1 ; row 200 ; col 500 ; clientarea 500, 250 ; TITLE 'GRID DEMO' ; WINDOWTYPE MAIN ; NOSIZE // start search Define Button bt_search Row 20 Col 20 width 175 Caption 'Search' Action google() End Button // search define TEXTBOX tb_text row 60 col 20 height 23 width 350 VALUE "hmg forum" end textbox ON KEY ESCAPE ACTION ThisWindow.Release end window // activate window ACTIVATE WINDOW form1 return nil // open browser and search function google() local cHtml := "" local fn_html := "search.html" cHtml += '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">' cHtml += '<html>' cHtml += '<head>' cHtml += ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' cHtml += ' <title>Hmg Google search</title>' cHtml += '</head>' cHtml += '<body>' // insert search string cHtml += '<meta http-equiv="refresh" content="0; url=http://google.com/search?q='+ strtran(getproperty("form1","tb_text","Value"),' ','+') + '">' cHtml += '</body>' cHtml += '</html>' // write modified model to a temp. file hb_memowrit( fn_html, cHtml) // execute this html file, windows OS opens iexplorer or chrome or // whatever in function of file extension association defined in windows. execute file (fn_html) return nil
Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?
Hi,
ok
I run and build this demo with minigui so 'execute file' is a known statement.
you simply replace
#include <hmg.ch>
with
include <minigui.ch>
In text mode use only the following function below. This should work.
Pass the search string as argument.
Regards
Hans
ok
I run and build this demo with minigui so 'execute file' is a known statement.
you simply replace
#include <hmg.ch>
with
include <minigui.ch>
In text mode use only the following function below. This should work.
Pass the search string as argument.
Regards
Hans
Code: Select all
// open browser and search
function google( cSearch )
local cHtml := ""
local fn_html := "search.html"
cHtml += '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
cHtml += '<html>'
cHtml += '<head>'
cHtml += ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
cHtml += ' <title>Hmg Google search</title>'
cHtml += '</head>'
cHtml += '<body>'
// insert search string
cHtml += '<meta http-equiv="refresh" content="0; url=http://google.com/search?q='+ cSearch + '">'
cHtml += '</body>'
cHtml += '</html>'
// write modified model to a temp. file
hb_memowrit( fn_html, cHtml)
// execute this html file, windows OS opens iexplorer or chrome or
// whatever in function of file extension association defined in windows.
execute file (fn_html)
return nil
-
- Posts: 197
- Joined: Thu Jul 16, 2020 5:42 pm
- DBs Used: DBF
Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?
Hans,
Thanks but minigui.ch is already one of the includes. Since I compiled with text mode /C, it doesn't link in the libraries that include the EXECUTE FILE command, and reports it as an external.
I can't even find where EXECUTE FILE is defined.
If I use the library that **I think** is supposed to contain ShellExecute() and try to link it in
or
with the library in the compile.bat batch file
/LE c:\minigui\Harbour\lib\hbwin
, the linker complains that it's an unresolved external.
Thanks but minigui.ch is already one of the includes. Since I compiled with text mode /C, it doesn't link in the libraries that include the EXECUTE FILE command, and reports it as an external.
I can't even find where EXECUTE FILE is defined.
If I use the library that **I think** is supposed to contain ShellExecute() and try to link it in
Code: Select all
REQUEST SHELLEXECUTEEX
Code: Select all
REQUEST SHELLEXECUTE
/LE c:\minigui\Harbour\lib\hbwin
, the linker complains that it's an unresolved external.
hansmarc wrote: ↑Tue Aug 30, 2022 8:10 pm Hi,
ok
I run and build this demo with minigui so 'execute file' is a known statement.
you simply replace
#include <hmg.ch>
with
include <minigui.ch>
In text mode use only the following function below. This should work.
Pass the search string as argument.
Regards
Hans
Code: Select all
// open browser and search function google( cSearch ) local cHtml := "" local fn_html := "search.html" cHtml += '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">' cHtml += '<html>' cHtml += '<head>' cHtml += ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' cHtml += ' <title>Hmg Google search</title>' cHtml += '</head>' cHtml += '<body>' // insert search string cHtml += '<meta http-equiv="refresh" content="0; url=http://google.com/search?q='+ cSearch + '">' cHtml += '</body>' cHtml += '</html>' // write modified model to a temp. file hb_memowrit( fn_html, cHtml) // execute this html file, windows OS opens iexplorer or chrome or // whatever in function of file extension association defined in windows. execute file (fn_html) return nil
Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?
Hi,
small correction in last sample :
replace line
cHtml += '<meta http-equiv="refresh" content="0; url=http://google.com/search?q='+ cSearch + '">'
with
cHtml += '<meta http-equiv="refresh" content="0; url=http://google.com/search?q='+ strtran(cSearch,' ','+') + '">'
Each word in the search string must be separated with the '+' sign.
So replace 'spaces' between words with '+'.
Regards
Hans
small correction in last sample :
replace line
cHtml += '<meta http-equiv="refresh" content="0; url=http://google.com/search?q='+ cSearch + '">'
with
cHtml += '<meta http-equiv="refresh" content="0; url=http://google.com/search?q='+ strtran(cSearch,' ','+') + '">'
Each word in the search string must be separated with the '+' sign.
So replace 'spaces' between words with '+'.
Regards
Hans
- dragancesu
- Posts: 930
- Joined: Mon Jun 24, 2013 11:53 am
- DBs Used: DBF, MySQL, Oracle
- Location: Subotica, Serbia