Communicate / Work with a nativ Application (EXE)

Just starting out? Need help? Post your questions and find answers here.
nicolaus
Posts: 6
Joined: Mon Mar 03, 2014 6:09 pm

Communicate / Work with a nativ Application (EXE)

Post 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
Fred
Site Admin
Posts: 1510
Joined: Mon Feb 24, 2014 10:51 am

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

Post 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())
nicolaus
Posts: 6
Joined: Mon Mar 03, 2014 6:09 pm

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

Post 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!
e2robot
Posts: 38
Joined: Wed Mar 19, 2014 8:34 am

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

Post 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
nicolaus
Posts: 6
Joined: Mon Mar 03, 2014 6:09 pm

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

Post 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
e2robot
Posts: 38
Joined: Wed Mar 19, 2014 8:34 am

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

Post 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
Fred
Site Admin
Posts: 1510
Joined: Mon Feb 24, 2014 10:51 am

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

Post by Fred »

That's true, a native CGI lib could be useful
nicolaus
Posts: 6
Joined: Mon Mar 03, 2014 6:09 pm

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

Post 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
Post Reply