Page 1 of 3
How to execute a google/yahoo/duckduck search from command line, or Harbour?
Posted: Tue Aug 30, 2022 3:31 pm
by HGAutomator
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.
Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?
Posted: Tue Aug 30, 2022 3:49 pm
by serge_girard
Hi!
You will have to start google too...!
c:\Progra~1\Google\Chrome\Application\chrome.exe
www.google.com/search?q=what+the
Serge
Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?
Posted: Tue Aug 30, 2022 4:13 pm
by HGAutomator
Yes. of course. Thanks, Serge.
Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?
Posted: Tue Aug 30, 2022 6:11 pm
by HGAutomator
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"'
Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?
Posted: Tue Aug 30, 2022 7:30 pm
by hansmarc
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?
Posted: Tue Aug 30, 2022 7:48 pm
by HGAutomator
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.
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?
Posted: Tue Aug 30, 2022 8:10 pm
by hansmarc
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?
Posted: Tue Aug 30, 2022 8:30 pm
by HGAutomator
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.
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?
Posted: Tue Aug 30, 2022 8:46 pm
by hansmarc
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
Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?
Posted: Wed Aug 31, 2022 6:19 am
by dragancesu