Server side (xampp): how to run external CGI/ exe

Just starting out? Need help? Post your questions and find answers here.
morosh
Posts: 27
Joined: Mon Feb 02, 2015 7:48 pm

Server side (xampp): how to run external CGI/ exe

Post by morosh »

Hello:
I'm trying to run an external exe from browser server side, I found two snippets in another post (http://forums.spiderbasic.com/viewtopic.php?f=6&t=292), I tried them in xampp, it didn't works, it seems I'm missing something:
SpiderBasic file "Test.sb":

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/cgi-bin/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
I made "Create App", this generates "test.html" and "test.js", I've copied this two files to c:\xampp\htdocs\test\, I've copied there the spiderbasic librairies as well.

then in PureBasic (v5.30) , I've created "upper.pb" (CGI libs already installed)

Code: Select all

CGI_In()
string$=CGI_Val("string")
string$=UCase(string$) 
CGI_Header()
CGI_Out(string$)
End
I create the executable "upper.exe" and put it in c:\xampp\cgi-bin

Going back to C;\xampp\htdocs\test\, clicking on test.html, then inside to "To Upper" button gives "Failed".

I didn't understand the line; HTTPRequest(#PB_HTTP_Get, "http://127.0.0.1/upper.pbe?string="+temp$, "", @UpperWeb())
what upper.pbe stands for?

any help is appreciated.
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Server side (xampp): how to run external CGI/ exe

Post by Peter »

morosh wrote:what upper.pbe stands for?
this might be the name of the executable.

so you have to rename your "upper.exe" to "upper.pbe" or you have to change your HttpRequest from "...upper.pbe?string..." to "...upper.exe?string..."

Greetings ... Peter
morosh
Posts: 27
Joined: Mon Feb 02, 2015 7:48 pm

Re: Server side (xampp): how to run external CGI/ exe

Post by morosh »

Yes, that what I supposed
I already renamed upper.exe to upper.pbe, but it didn't works
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Server side (xampp): how to run external CGI/ exe

Post by Peter »

this is a working example

PureBasic 5.60 (with native CGI support):

Code: Select all

If Not InitCGI() Or Not ReadCGI()
  End
EndIf

Define myString.s = CGIParameterValue("string")

WriteCGIHeader("Access-Control-Allow-Origin", "*")

WriteCGIHeader(#PB_CGI_HeaderContentType, "text/plain", #PB_CGI_LastHeader)

WriteCGIString(UCase(myString))
SpiderBasic:

Code: Select all

Procedure HTTPRequestCallback(Success, Result.s)
  Debug Success
  Debug Result
EndProcedure

Define myString.s = "uppercase"

HTTPRequest(#PB_HTTP_Get, "http://localhost/cgi-bin/upper.exe?string=" + myString, "", @HTTPRequestCallback())
Greetings ... Peter
morosh
Posts: 27
Joined: Mon Feb 02, 2015 7:48 pm

Re: Server side (xampp): how to run external CGI/ exe

Post by morosh »

Works great!!!
Thank you very much Peter!!
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Server side (xampp): how to run external CGI/ exe

Post by Peter »

morosh wrote:Works great!!!
Fine! :)

If you want, you can try SpiderBite (sorry, the readme is in german, but you can use google translate)

With SpiderBite you are able to write something like this:

Code: Select all

XIncludeFile "[YourPathTo]/SpiderBite.sbi"

#SpiderBite_Profile = "default"

EnablePbCgi
  
  Procedure.s Upper(myString.s)
    ProcedureReturn UCase(myString)
  EndProcedure
  
DisablePbCgi

Define myString.s
myString = "uppercase"
Debug Upper(myString)
Greetings ... Peter
morosh
Posts: 27
Joined: Mon Feb 02, 2015 7:48 pm

Re: Server side (xampp): how to run external CGI/ exe

Post by morosh »

Wonderful, very interesting
Go on Peter!! :D
Post Reply