Looping a GOSUB

95 views
Skip to first unread message

Johan Liebenberg

unread,
Jun 4, 2021, 8:29:37 AM6/4/21
to jBASE
Building a small batch file to run on a Window jBase server.

Batch file executes a curl command build inside the jBase program.

I 1st tried to EXECUTE the curl command CAPTURING RESULTS, but the remote server returns an error. I filtered all the illegal character out of the curl command just in case. No luck.This happens to work flawlessly on a Linux server.

So the next approach is to create a DOS batch file and execute the batch file with the curl command inside the batch file. Works 1st time but then the trouble starts:

So I have a GOSUB RUNCMD that calls the sub below with the curl command inside the CMD variable:

RUNCMD:

     OSDELETE 'temp.bat'

    EXECUTE 'touch temp.bat' CAPTURING JUNK

    OSOPEN 'temp.bat' TO TEMPDOSFILE THEN

        OSBWRITE CMD ON TEMPDOSFILE AT 0

        OSCLOSE TEMPDOSFILE

        EXECUTE 'temp.bat' CAPTURING RESULTS

    END

    OSDELETE 'temp.bat'

 RETURN

With the debugger turned on, outside RUNCMD sub, I can follow the progress through the sub line by line, everything works and the remote server receives the curl command correctly and returns the correct data in the RESULTS variable. All good. When the execution gets to the RETURN command, one expects it to jump back to the 1st line after the GOSUB RUNCMD, but instead it jumps back to the RUNCMD: label and it repeats the sub over and over in a loop that you can not break out of.

Surely I am very tired because it is late and I am missing something really really obvious. Thanks for looking :)

Peter Falson

unread,
Jun 4, 2021, 9:37:37 AM6/4/21
to jb...@googlegroups.com
What version of jBASE are you using? We support curl natively now 

https://docs.zumasys.com/jbase/miscellaneous/jcurl/#additional-helper-functions

Sent from my iPhone

On Jun 4, 2021, at 5:29 AM, Johan Liebenberg <joha...@gmail.com> wrote:


--
--
IMPORTANT: T24/Globus posts are no longer accepted on this forum.
 
To post, send email to jB...@googlegroups.com
To unsubscribe, send email to jBASE-un...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jBASE?hl=en

---
You received this message because you are subscribed to the Google Groups "jBASE" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbase+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jbase/64144341-a743-4e2b-9824-8cfda8f609f9n%40googlegroups.com.

Johan Liebenberg

unread,
Jun 6, 2021, 12:00:08 PM6/6/21
to jBASE
jBASE 5.2.31 on Windows Server 2012.

Yes thanks I saw the jCURL command and I will investigate in future to do a switch over. Anyway, I got the batch file thing to work by not calling the subroutine and instead calling the same code in 3 different places. More cleanup to do later.

Thanks :)

Jim Idle

unread,
Jun 9, 2021, 1:13:46 AM6/9/21
to jBASE
I usually find that it is better to say what you are trying to do first. Maybe your approach is not optimal? As in tell us:

"I need to contact an http server at http:// and retrieve xyz"

Whereas here you are assuming your approach is the correct one, then saying it isn't working. we should probably work out why you are seeing what you seem to be seeing, but it may well be that your approach is incorrect.

The compiler will not generate bad code for GOSUB and RETURN - if it did, a lot more people would be complaining ;). It tends to make me think that you are not executing the binary that you think you are. Maybe run from a command line instead of jsh for instance. Also, when executing external scripts, you would likely be better specifying EXECUTE with CHAR(255):"<shell indicator":"curl ....." - not specifying a shell may well be why EXECUTE of your command line is not working.

You should also use the additional clauses in EXECUTE to capture exit codes and errors etc. Your code is just assuming that it works, which is never a good idea.

I would also recommend Linux over Windows, but that's just a preference. Things always seem to work better.

So, what are you actually trying to do here? There are probably 20 different ways if we know what you are doing.

Jim


Johan Liebenberg

unread,
Jun 9, 2021, 6:55:05 AM6/9/21
to jBASE
Thanks for the reply.
Yes as I said, it works just fine on Linux. I am trying to send some data to another server, just a few headers with values. The code does not need to check status as it should not interrupt the current process if it fails for any reason whatsoever. I will pick it up on the remote server if the process did not call in successfully. Anyway, taking the exact code out of the gosub fixed it. Same code, just no gosub and no return. Works fine on Linux, does not work on Windows.
I will rewrite some of it when I start using the jCurl command. Will have to figure out if it is available on the older versions of jBase.

Jim Idle

unread,
Jun 10, 2021, 1:58:16 AM6/10/21
to jBASE
On Wed, Jun 9, 2021 at 6:55 PM Johan Liebenberg <joha...@gmail.com> wrote:
Thanks for the reply.
Yes as I said, it works just fine on Linux. I am trying to send some data to another server, just a few headers with values. The code does not need to check status as it should not interrupt the current process if it fails for any reason whatsoever.

I would probably not do this from jBASE at all then, just monitor a transfer directory and write the data to be transferred there and move on. Otherwise your main program will hang around waiting for the curl etc. I don't know if the receiving end is jBASE or something else, but message queues are your friend, or even something as simple as scp. Think in parallel terms. 

 
I will pick it up on the remote server if the process did not call in successfully. Anyway, taking the exact code out of the gosub fixed it. Same code, just no gosub and no return. Works fine on Linux, does not work on Windows.

Which is why you should work out what is going on with your subroutine and EXECUTE. You may have found a way to get around it by duplicating code, but that is more likely to be masking the actual problem, which may come back to bite you later.

 

I will rewrite some of it when I start using the jCurl command. Will have to figure out if it is available on the older versions of jBase.

But is using a form of curl really the correct way to do this?

 

Johan Liebenberg

unread,
Jun 10, 2021, 11:58:53 AM6/10/21
to jBASE
On Thursday, June 10, 2021 at 3:58:16 PM UTC+10 ji...@temporal-wave.com wrote:
On Wed, Jun 9, 2021 at 6:55 PM Johan Liebenberg <joha...@gmail.com> wrote:
Thanks for the reply.
Yes as I said, it works just fine on Linux. I am trying to send some data to another server, just a few headers with values. The code does not need to check status as it should not interrupt the current process if it fails for any reason whatsoever.

I would probably not do this from jBASE at all then, just monitor a transfer directory and write the data to be transferred there and move on. Otherwise your main program will hang around waiting for the curl etc. I don't know if the receiving end is jBASE or something else, but message queues are your friend, or even something as simple as scp. Think in parallel terms. 

Data comes from jBase. The curl command uses a timeout  setting so it will not run longer than 4 seconds before it terminates. Generally it takes only around 100ms.
 
I will pick it up on the remote server if the process did not call in successfully. Anyway, taking the exact code out of the gosub fixed it. Same code, just no gosub and no return. Works fine on Linux, does not work on Windows.

Which is why you should work out what is going on with your subroutine and EXECUTE. You may have found a way to get around it by duplicating code, but that is more likely to be masking the actual problem, which may come back to bite you later.

Planning to switch to jCurl in future. This code will eventually change and the loop will not be necessary because the network infrastructure will change. Until then I can live with the issue.
 

I will rewrite some of it when I start using the jCurl command. Will have to figure out if it is available on the older versions of jBase.

But is using a form of curl really the correct way to do this?
Talking to a remote API via SSL, this is the easiest  way I can think of. Yes you can probably use any number of other solutions. Curl works, it's platform independent, well proven and capable. Nothing to setup or configure, just curl :)   - I should copyright that ;)

Rick Weiser

unread,
Jun 10, 2021, 11:59:48 AM6/10/21
to jBASE
WOW, a jIdle sighting!!

Jim Idle

unread,
Jun 10, 2021, 11:28:51 PM6/10/21
to jBASE
None of your lip Weiser ;)

Reply all
Reply to author
Forward
0 new messages