Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a response from a Perl script 2

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I have a VFP6 app which uploads a file onto a remote server, processes the contents of the file and populates a MySQL database with the contents. That is all working fine but I want to pass some information back from the server to the calling VFP6 application. Is there an API for this or is there a much simpler approach? I am just looking for a bit of guidance on this.

Keith
 
I want to pass some information back from the server to the calling VFP6 application.

I guess that I am unclear on what is going where and being handled by what application.
And somewhere I'd guess that PERL is involved since you mention it in your Post Topic

1. A VFP6 Application sends (uploads) a file onto some remote server.
2. Something processes the contents of the uploaded file
3. Something populates a MySQL data table within a MySQL database located Somewhere

Now you want your VFP6 application to get some information back - from what?
* The MySQL data table?
* The something which processed the received file?

Can your VFP6 application 'see' the MySQL Database and just read back the results?

Good Luck,
JRB-Bldr

 
I would echo JRB's questions and comments.

If the information you want to retrieve is in the MySQL database, you should be able to get at that via ODBC. If it's somewhere else on the server - well, it depends on what type of server and how you connect to it. If you could give us that information, we can probably point you in the right direction.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I'm guessing that you want the VFP app to know when the other app has done something. In VFP 9, there are some fairly cool ways to do this, but in VFP 6, you just have to do it the old-fashioned way.

Have your other application create a file in a known location.
Have a timer in your application poll that known location to see whether the file is there.

Tamar
 
I tried to keep the question simple but obviously I worded it wrongly.

Tamar
You are not far off with your guess and that solution will work, thanks.
I was hoping for a solution which would return an immediate response.

I was just wondering if there was a function similar to Loadvars in Flash, where I can call a URL and get a response string from it directly back into the VFP6 program.

Keith
 
Well, if you call a perl script, how do you do it? Directly? s Perl installed on the computer locally, or via a HTTP Request?
If Perl is called by a http request, it's the same as any http request, you get a response, you just have to let the perl script write something back.

If you call a perl script locally, it's about the same as calling a bat or an EXE, you can use stdout to receive something back. It's a bit more complicated to create a process, get the process handle and wait for the end of the process.

As you fill MySQL tabe in the end this is something you could do from VFP via MySQL ODBC and SQL Passtrough, also in VFP6.

Bye, Olaf.
 
>similar to Loadvars in Flash, where I can call a URL and get a response string from it directly back

From that I guess you "call a URL" to call the perl script to. The technical term rather is to make a http request. And by definition you get a response. It depends on the perl script, if you get a hint on it being done with mysql, and if it was successful or not. In the normal case the response only comes back, when the script finishes, so that would already be a hint, even if there is nothing in the response body.

In HTTP request it doesn't matter what language the script or module or applet or whatever runs, the http request is addressed to a web server in the first place, and the webserver then does trigger whatever is associated with the type of request, and that works by the final extension quite like in DOS or windows, eg .cgi triggers perl. Flash mostly is indirectly triggered by having a flash object embedded in some html page coming from whatever script type or even from a static html page. But in the end it's IIS or apache or some other webserver responding to you, and even if the perl scripts just takes in data, inserts it into mysql and finishes, without reporting back, you get a response to your http request from the webserver.

So again asked: How do you call the perl script?

Bye, Olaf.
 
I was just wondering if there was a function similar to Loadvars in Flash, where I can call a URL and get a response string from it directly back into the VFP6 program.

Would the OpenURL method of the Internet Transfer Control be what you want?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
The HTTP request is from a VFP6 app on my local computer, it is called from a form using 'navigateto'. The Perl script is on the remote server and the URL is in the form of 'The script does some things but what it does is not relevant.
At the end it prints a string of characters and I want to catch them in the calling VFP program.
I know how to call the Perl script and print a response but I need to know how to capture the string in VFP.
Please don't get side tracked with what I may or may not be sending back or where it comes from, what it says, how long the string is etc. etc. it is a short string of letters.

Keith
 
Keith,

Basically, you pass a URL to OpenURL(), and it sends back whatever text is at that URL. There's no reason why the URL shouldn't be a Perl script. You can think of it as the programmatic equivalent of typing the URL in a browser's address bar. Whatever you would then see in the browser's window is what the function returns.

The Internet Transfer Control is one of the ActiveX controls that comes with VFP (all versions). I've found that it usually works pretty well.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I found this as an example but it errors, too many arguments.

Code:
declare integer ShellExecute in shell32.dll ;
int owner,;
string verb,;
string command,;
string params,;
string working,;
int shwnd

ShellExecute(0,"open","[URL unfurl="true"]http://www.mysite.co.uk/cgi-bin/httpreq.pl",0,0,1)[/URL]

The search goes on.

Keith
 
A bit more delving and I found this to work
Code:
oInet=CREATEOBJECT("inetctls.inet")
oInet.protocol = 4   && Set to HTTP
lcHttp = oInet.openurl("[URL unfurl="true"]http://www.mysite.co.uk/cgi-bin/httpreq.pl",[/URL] 0)
? lcHttp

Filezilla must use the same system as it stops working when that is running.

Keith
 
Calling ShellExecute() isn't going to do what you want. It will simply launch the script in the user's default browser.

What you want is something like this:

Code:
oInet = CreateObject("InetCtls.Inet") 
lcReply = oInet.OpenURL("[URL unfurl="true"]http://www.mysite.co.uk/cgi-bin/httpreq.pl")[/URL]

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks Mike, now it is your turn to cross posts.
The code works but I sometimes get an error that an instance is still running, should I be destroying the object after use in some way?

Keith
 
Not sure about that. Some of the functions of the control run asynchronously, and so you need to test for completion, but I don't think OpenURL is one of them.

You could try adding this immediately after the call to OpenURL:

Code:
DO WHILE oInet.StillExecuting
ENDDO

But is shouldn't be necessary.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
OpenURL is not waiting for the script to finish. If you'd do it in other ways, like URLDownloadToFile or via MSXML2.XMLHTTP.6.0 these work asynchronous, let alone because perl may spawn a thread. Then you get a reponse befor ethe script finishes. This is not quite normal, but then you need to know the perl code. If it's not yours you could simply wrap the calls in TRY CATCH. If you get the error you know the script is still busy not reacting. Nothing is broken, you simply repeat your request later.

Bye, Olaf.
 
The error I get is
OLE |Dispatch esception code 0 from Inet. Still executing last request

It is my Perl code, a very simple script for testing, I doubt if it is still running.
Code:
#!/usr/bin/perl
my $query = new CGI;
print "Content-type: text/html\n\n";
print "Yippee";

Keith
 
I can't imagine that the Perl script would cause this error. If I'm right in saying that OpenURL is synchronous, it's going to wait for the script to finish running come what may. There must be something else going on here.

Sorry I can't suggest anything off hand.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
OK, but I think the new CGI is exactly doing what I suspected, it's spawning a new thread that never ends.

Usin Mikes code, do you get the "Yippie" string in lcReturn? If yes, you're almost there, something causes the perl engine not to end, as said I suspect the "new CGI".

I am no perl pro, though, perhaps ask in a perl forum, how to write a simple hello world perl sample, that returns soething, which is returned as http response by the web server.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top