Page 1 of 1

Communicate / Work with a nativ Application (EXE)

Posted: Fri Apr 03, 2015 8:19 am
by nicolaus
Hi all,

is there a way in SpiderBasic, to work / communicate with native applications like a exe in Windows?
If is so, can any one show me a small sample how i must start to do this?

Thanks and a nice easter to all of you!

Nico

Re: Communicate / Work with a nativ Application (EXE)

Posted: Tue Apr 07, 2015 6:25 am
by Fred
From the client side (browser), you can't lanuch an exe or anything outside the browser. But you can do it server-side, with a CGI or a PHP script which launch the exe (you can call the URL from SpiderBasic with HTTPRequest())

Re: Communicate / Work with a nativ Application (EXE)

Posted: Tue Apr 07, 2015 9:14 am
by nicolaus
Fred wrote:From the client side (browser), you can't lanuch an exe or anything outside the browser. But you can do it server-side, with a CGI or a PHP script which launch the exe (you can call the URL from SpiderBasic with HTTPRequest())
Thanks for replay.
Do you have a smal sample how we can do this?

What i need to do is:
- start a exe
- read stdout or pull data from a DB
- close the exe

Thanks for your help!

Re: Communicate / Work with a nativ Application (EXE)

Posted: Tue Apr 14, 2015 7:51 am
by e2robot
Here is a sample of client / server comms in spiderbasic / purebasic

When you click the button it sends string to cgi which uppers the string and sends back the result
Spiderbasic will then update the textgadget

You need the CGI Lib for Purebasic for server end.

You also need to run the Spiderbasic and the CGI Purebasic from the same webserver to avoid cross domain request problems.
i.e. it will not work from the IDE with default Apache setup

In my example both are served from a local Apache server on Windows box.

You also have to configure Apache to allow CGI etc.

However you can make it work from IDE by modifying the following in Apache.

Add in mod_headers.so

and in Directory section add
Header set Access-Control-Allow-Origin "*"

Handy for testing only......

Spiderbasic

Code: Select all

Procedure UpperWeb(Success, Result$)
  If Success
    SetGadgetText(3,Result$)
  Else
    Debug "Failed"
  EndIf
EndProcedure


Procedure getbutton()
  temp$=GetGadgetText(3)  
  HTTPRequest(#PB_HTTP_Get, "http://127.0.0.1/upper.pbe?string="+temp$, "", @UpperWeb())
  
EndProcedure

If OpenWindow(1, 100, 100, 250, 75, "Test", #PB_Window_TitleBar)
  ButtonGadget(2, 20, 30, 75, 30, "To Upper")
  StringGadget(3, 120, 30, 75, 30, "abc")
  BindGadgetEvent(2,@getbutton(), #PB_EventType_LeftClick )
EndIf

Purebasic

Code: Select all

CGI_In()
string$=CGI_Val("string")
string$=UCase(string$)  
CGI_Header()
CGI_Out(string$)
End

Re: Communicate / Work with a nativ Application (EXE)

Posted: Tue Apr 14, 2015 8:22 am
by nicolaus
e2robot wrote:Here is a sample of client / server comms in spiderbasic / purebasic

When you click the button it sends string to cgi which uppers the string and sends back the result
Spiderbasic will then update the textgadget

You need the CGI Lib for Purebasic for server end.

You also need to run the Spiderbasic and the CGI Purebasic from the same webserver to avoid cross domain request problems.
i.e. it will not work from the IDE with default Apache setup

In my example both are served from a local Apache server on Windows box.

You also have to configure Apache to allow CGI etc.

However you can make it work from IDE by modifying the following in Apache.

Add in mod_headers.so

and in Directory section add
Header set Access-Control-Allow-Origin "*"

Handy for testing only......

Spiderbasic

Code: Select all

Procedure UpperWeb(Success, Result$)
  If Success
    SetGadgetText(3,Result$)
  Else
    Debug "Failed"
  EndIf
EndProcedure


Procedure getbutton()
  temp$=GetGadgetText(3)  
  HTTPRequest(#PB_HTTP_Get, "http://127.0.0.1/upper.pbe?string="+temp$, "", @UpperWeb())
  
EndProcedure

If OpenWindow(1, 100, 100, 250, 75, "Test", #PB_Window_TitleBar)
  ButtonGadget(2, 20, 30, 75, 30, "To Upper")
  StringGadget(3, 120, 30, 75, 30, "abc")
  BindGadgetEvent(2,@getbutton(), #PB_EventType_LeftClick )
EndIf

Purebasic

Code: Select all

CGI_In()
string$=CGI_Val("string")
string$=UCase(string$)  
CGI_Header()
CGI_Out(string$)
End

Hi,

thnaks for the sample.
I will try it if i'm back at home.

Cheers,
Nico

Re: Communicate / Work with a nativ Application (EXE)

Posted: Tue Apr 14, 2015 8:31 am
by e2robot
No problems......I have a full invoicing / job tracking database system written using this tech.

The cgi library for Purebasic I used is from

http://www.reelmedia.org/cgi-bin/PurePr ... &sub=ASM52

Would be nice to see CGI built into Purebasic now with have Spiderbasic to play with too.

Phil

Re: Communicate / Work with a nativ Application (EXE)

Posted: Wed Apr 15, 2015 6:53 am
by Fred
That's true, a native CGI lib could be useful

Re: Communicate / Work with a nativ Application (EXE)

Posted: Tue Apr 21, 2015 7:23 am
by nicolaus
Fred wrote:That's true, a native CGI lib could be useful
@Fred, so we can hope for a native CGI lib in one of the next PB Versions? That will be very nice! ;)

Thanks,
Nico