Michael and others,
Below is the UniBasic program using wIntegrate calls that will execute a Curl command and retrieve a json file from a website. The results.json is placed in a newly created Pie_Downloads directory. Note: directories can't have a blank space in the name. From this point on you can access the results.json file and do as you want locally on the client.
-Peter G
PATHNAME = "C:\Pie_Downloads"
FILENAME = "CURLCOMMAND.BAT"
STMT = ""
STMT<-1> = "@ECHO OFF"
STMT<-1> = "echo Running curl command:"
STMT<-1> = "echo."
STMT<-1> = "curl.exe -o ":PATHNAME:"\results.json
http://www.example.com/index.html"STMT<-1> = "echo."
STMT<-1> = "cmd.exe /k"
*
* Verify that the Download folder is there.
*
CALL WIN.PCDIR(PATHNAME, FOUND)
IF NOT(FOUND) THEN
*
* Create The "Download Folder" If Not Found.
*
CALL WIN.PCMKDIR(PATHNAME)
END
*
* Opens The File Or Creates The File.
*
CALL WIN.PCOPEN("CURL", PATHNAME:"\":FILENAME, FOUND)
IF NOT(FOUND) THEN
*
* Create The "CURLCOMMAND.BAT" If Not Found.
*
CALL WIN.PCCREATE(PATHNAME:"\":FILENAME)
*
* Opens The File Or Creates The File.
*
CALL WIN.PCOPEN("CURL", PATHNAME:"\":FILENAME, FOUND)
END
*
* Writes The Contents To The File.
*
CALL WIN.PCWRITE("CURL", STMT, "TEXT") ;* "TEXT" Swaps a crlf
*
* Closes The File. - Very Important
*
CALL WIN.PCCLOSE("CURL")
*
* Execute The Bat Program.
*
CALL WIN.PCRUN2(PATHNAME:"\":FILENAME, "", 0, RESP)
STOP
------------------------------
Peter Gonzalez
programmer
Self Registered
University City MO United States
------------------------------
Original Message:
Sent: 09-15-2021 14:27
From: Michael Belme
Subject: Executing a API curl command from UniBasic
Hi Peter,
I spent some time working on this and came up with something that works. I'm not quite sure how you want this setup to run on the client PC, so just went with what works first.
The BASIC program using the wIntegrate host routines looks like this:
CALL WIN.PCRUN2("C:\users\mbelme\desktop\curlcommand.bat","",0, RESP)
IF RESP < 32 THEN
PRINT "Failed to run curl, error code: ":RESP
END ELSE PRINT "curl command started"
So when you run this it will launch a Windows batch script on the client PC located on my user's desktop called curlcommand.bat. That batch script is setup like this inside:
@ECHO OFF
echo Running curl command:
echo.
curl.exe -o c:\users\mbelme\desktop\out.json http://www.example.com/index.html
echo.
cmd.exe /k
It will open a Windows command prompt and run the command on the client moving focus to that window and off wIntegrate. Obviously you can modify that however you want it setup. The last line of 'cmd.exe /k' leaves the command prompt window open. Get rid of that line if you want it to just self-close once it runs. Refer to the wIntegrate Host Subroutines Reference for more info on WIN.PCRUN2.
I tried passing the curl.exe command direct into WIN.PCRUN2, but I couldn't find any combo to get it to run and successfully create that output file. So this was the combo I came up with to get it to run properly. Let me know if you have questions.
Thanks,
Michael
------------------------------
Michael Belme
Technical Support
Rocket Internal - All Brands
DENVER CO United States
Original Message:
Sent: 09-15-2021 11:07
From: Peter Gonzalez
Subject: Executing a API curl command from UniBasic
Michael,
Is you curl command being execute on the Unidata Windows server? I'm trying to execute the curl command on the client side and capture the data there. Would Integrate's WIN.EXPORT WIN.IMPORT do what I'm looking for?
Our version of Unidata HPUX is very old and it does not have the "call..." extensions.
Thanks,
-Peter G
------------------------------
Peter Gonzalez
programmer
Self Registered
University City MO United States
Original Message:
Sent: 09-13-2021 15:26
From: Michael Belme
Subject: Executing a API curl command from UniBasic
Hi Peter,
I gave your program a test on UniData 8.2.3 on Windows. It seems to work and the out.json file will be created at the OS level in the account you run the program from:
:CT BP CURLTEST
BP:
CURLTEST
STMT = "curl -o out.json http://www.example.com/index.html"
PCPERFORM STMT
END:
:RUN BP CURLTEST
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1256 100 1256 0 0 1256 0 0:00:01 --:--:-- 0:00:01 39250
:
So this should work. My only programming difference is the final 'END' last line. Do you get an error message or just no response? I started with 'curl -V' as the command to make sure I was getting output back first via PCPERFORM before moving on to the request.
We also have the callHTTP extension within UniBASIC if you'd like to run the HTTP request directly in BASIC without the external curl call.
Feel free to open a support case with Rocket if you'd like to discuss further.
Thanks,
Michael Belme
Rocket U2 Support
------------------------------
Michael Belme
Technical Support
Rocket Internal - All Brands
DENVER CO United States
Original Message:
Sent: 09-13-2021 12:53
From: Peter Gonzalez
Subject: Executing a API curl command from UniBasic
Hello group!
I should know this but it's not working for me. I'm trying to execute a API curl command from my Unidata Unibasic flavor running HP/UX system. The emulator is wIntegrate but I don't think that matters. What is the correct syntax to execute an API Curl command from my PC? Thanks!
*** This works from command prompt ***
C:\Users\gonzalp>curl -o out.json http://www.example.com/index.html
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1256 100 1256 0 0 1256 0 0:00:01 --:--:-- 0:00:01 26723
*** This does not work from UniBasic ***
STMT = 'curl -o out.json http://www.example.com/index.html'
PCPERFORM STMT
------------------------------
Peter Gonzalez
programmer
Self Registered
University City MO United States
------------------------------