Page 2 of 3

Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?

Posted: Wed Aug 31, 2022 6:29 am
by serge_girard
HGAut:

this works:

Code: Select all

cAPP := 'c:\Progra~1\Google\Chrome\Application\chrome.exe ' 
EXECUTE FILE "&cAPP "  PARAMETERS 'www.google.com/search?q=what+the'   

Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?

Posted: Wed Aug 31, 2022 8:20 am
by PeteWG
Hello guys,

You might want to try the below code. It's portable and UI independent (can be used on both console and GUI appls).

Code: Select all

/*
gsearch.prg
compile : hbmk2 -w3 -es2 gsearch
*/
PROC Main( cSearchFor )
	LOCAL nResult := GoogleSearch( hb_DefaultValue( cSearchFor, "Harbour Minigui -facebook" ) )

	IF nResult == 0
		? "Search string has been sent to your browser!"
	ELSE
	   ? "Cannot execute search command! Error code:" + hb_ntos(nResult)
	ENDIF
		
	RETURN
	
FUNCTION GoogleSearch( cSearchFor )
	LOCAL cCmd, nResult
	
	IF ! HB_ISSTRING( cSearchFor ) .OR. Empty( cSearchFor )
		RETURN -1
	ENDIF
	cSearchFor := hb_StrReplace( cSearchFor, {'"'=>"", " "=>"+"}  )
	cCmd       := " /Q /C start https://www.google.com/search"+'"?client=gtx&q=' + cSearchFor + '"'
	nResult    := hb_run( hb_GetEnv( "ComSpec" ) + cCmd )
	
	RETURN nResult
regards,
Pete

Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?

Posted: Wed Aug 31, 2022 9:30 am
by serge_girard
Thans Pete!

Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?

Posted: Wed Aug 31, 2022 10:37 am
by hansmarc
Hi Pete,

also a nice solution, no temporary html file has to be created but
in your sample a cmd command window appears a fraction of a second before opening the webbrowser.

Suggestion to prevent this with hb_run replace that line with :

ShellExecute(0, "open", "rundll32.exe","url.dll,FileProtocolHandler " + "https://www.google.com/search?q=" + cSearchfor, , 1)


Regards
Hans

Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?

Posted: Wed Aug 31, 2022 11:20 am
by HGAutomator
Thanks Dragancesu,

That's a good reference, but there's no problem with the search string itself, at this point.

Now, the problem is with HB_Run. It isn't interpreting the quote around the program path correctly in conjunction with the parameters. Also, it waits until the called program is finished before continuing it's process.

ShellExecute/EXECUTE FILE is the obvious alternative. Unfortunately, it doesn't seem possible to mix text mode, with ShellExecute. The link works, but then nothing is displayed in the application. You can't even display the menu.

I'm going to play with putting most of the command line in a batch file, and calling the batch file from HB_Run, maybe with cmd.exe /c.



Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?

Posted: Wed Aug 31, 2022 11:22 am
by HGAutomator
Peter,

Yes, this might work, thanks.
PeteWG wrote: Wed Aug 31, 2022 8:20 am Hello guys,

You might want to try the below code. It's portable and UI independent (can be used on both console and GUI appls).

Code: Select all

/*
gsearch.prg
compile : hbmk2 -w3 -es2 gsearch
*/
PROC Main( cSearchFor )
	LOCAL nResult := GoogleSearch( hb_DefaultValue( cSearchFor, "Harbour Minigui -facebook" ) )

	IF nResult == 0
		? "Search string has been sent to your browser!"
	ELSE
	   ? "Cannot execute search command! Error code:" + hb_ntos(nResult)
	ENDIF
		
	RETURN
	
FUNCTION GoogleSearch( cSearchFor )
	LOCAL cCmd, nResult
	
	IF ! HB_ISSTRING( cSearchFor ) .OR. Empty( cSearchFor )
		RETURN -1
	ENDIF
	cSearchFor := hb_StrReplace( cSearchFor, {'"'=>"", " "=>"+"}  )
	cCmd       := " /Q /C start https://www.google.com/search"+'"?client=gtx&q=' + cSearchFor + '"'
	nResult    := hb_run( hb_GetEnv( "ComSpec" ) + cCmd )
	
	RETURN nResult
regards,
Pete

Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?

Posted: Wed Aug 31, 2022 11:23 am
by HGAutomator
Hans,

Thanks, but ShellExecute and EXECUTE FILE isn't working. It's possible to link it in, but then the text mode application itself doesn't display anything.
hansmarc wrote: Wed Aug 31, 2022 10:37 am Hi Pete,

also a nice solution, no temporary html file has to be created but
in your sample a cmd command window appears a fraction of a second before opening the webbrowser.

Suggestion to prevent this with hb_run replace that line with :

ShellExecute(0, "open", "rundll32.exe","url.dll,FileProtocolHandler " + "https://www.google.com/search?q=" + cSearchfor, , 1)


Regards
Hans

Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?

Posted: Wed Aug 31, 2022 11:25 am
by HGAutomator
Serge,

Thanks, but EXECUTE FILE doesn't work with this text-mode app. The program runs, but there are no menus visible with which to select the menu item to run EXECUTE FILE or ShellExecute.

serge_girard wrote: Wed Aug 31, 2022 6:29 am HGAut:

this works:

Code: Select all

cAPP := 'c:\Progra~1\Google\Chrome\Application\chrome.exe ' 
EXECUTE FILE "&cAPP "  PARAMETERS 'www.google.com/search?q=what+the'   

Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?

Posted: Wed Aug 31, 2022 2:35 pm
by HGAutomator
Thanks, Pete. Everything's perfect.


https://drive.google.com/file/d/126Z-Kf ... sp=sharing

(If Google Drive says the video is still processing, ignore that message and just download it.)

Re: How to execute a google/yahoo/duckduck search from command line, or Harbour?

Posted: Wed Aug 31, 2022 3:26 pm
by serge_girard
HGAut

What is text-mode app? You mean DOS screen? Then this works:

Code: Select all

FUNCTION Main
REQUEST HB_GT_WIN_DEFAULT
cAPP := 'c:\Progra~1\Google\Chrome\Application\chrome.exe ' 
EXECUTE FILE "&cAPP "  PARAMETERS 'www.google.com/search?q=what+the'   
return