cURL Library on Linux

89 views
Skip to first unread message

Larry Rix

unread,
Mar 14, 2021, 9:51:44 AM3/14/21
to Eiffel Users
I am trying to get the cURL library to work on Linux.

No luck.

Clues?

Gary Smithrud (GMS134)

unread,
Mar 14, 2021, 1:07:03 PM3/14/21
to eiffel...@googlegroups.com
Details?

Sent from my iPhone

On Mar 14, 2021, at 9:51 AM, Larry Rix <lar...@moonshotsoftware.com> wrote:


I am trying to get the cURL library to work on Linux.

No luck.

Clues?

--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/d295b14f-331c-4ad9-ba24-9c9270b20995n%40googlegroups.com.

Larry Rix

unread,
Mar 14, 2021, 2:49:10 PM3/14/21
to Eiffel Users
Reference the cURL library in the project settings.


No work.

Ulrich Windl

unread,
Mar 15, 2021, 3:54:30 AM3/15/21
to eiffel...@googlegroups.com
>>> Larry Rix <lar...@moonshotsoftware.com> schrieb am 14.03.2021 um 14:51 in
Nachricht <d295b14f-331c-4ad9...@googlegroups.com>:
> I am trying to get the cURL library to work on Linux.

Maybe provide some details:

Her I have a packe with libcurl:
libcurl4-7.60.0-11.12.1.x86_64

Ulrich Windl

unread,
Mar 15, 2021, 4:49:00 AM3/15/21
to eiffel...@googlegroups.com
>>> "Ulrich Windl" <Ulrich...@rz.uni-regensburg.de> schrieb am 15.03.2021 um
08:54 in Nachricht <604F12B10200...@gwsmtp.uni-regensburg.de>:
>>>> Larry Rix <lar...@moonshotsoftware.com> schrieb am 14.03.2021 um 14:51 in
> Nachricht <d295b14f-331c-4ad9...@googlegroups.com>:
>> I am trying to get the cURL library to work on Linux.
>
> Maybe provide some details:
>
> Her I have a packe with libcurl:

Sorry: "Here I have a package with libcurl:"

> libcurl4-7.60.0-11.12.1.x86_64
>
>>
>> No luck.
>>
>> Clues?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Eiffel Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to eiffel-users...@googlegroups.com.
>> To view this discussion on the web visit
>>
> https://groups.google.com/d/msgid/eiffel-users/d295b14f-331c-4ad9-ba24-9c9270
>
>> b20995n%40googlegroups.com.
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Eiffel Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to eiffel-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/eiffel-users/604F12B1020000A10003FC97%40gws
> mtp.uni-regensburg.de.




Larry Rix

unread,
Mar 15, 2021, 8:01:37 AM3/15/21
to Eiffel Users
Good morning all!

I am unsure what other details would be helpful to you all or to me for that matter.

However—I can tell you the following:
  • I am on Linux Mint, which I think is a standard Debian distro (I think I have that right).
  • Typing "curl -v" at the command prompt tells me that curl is installed on my OS.
  • I am using Eiffel Studio 20.11 with the cURL library installed in the $ISE_LIBRARY folder.
I read my own notes on the Easy Curl Example page on eiffel.org, but those notes are for Windows, so I am unsure as to how they work or apply in a Linux distro.

What I can tell you is that I have the library listed in the ECF file.

Of further interest (and most likely unrelated) is that I even tried to "shell out" using the process and base_process libraries to see if I could get a call out to the shell and run cURL from the command line. This fails to work at any level, which really surprises me. Doing the shell-execute thing in Windows has always worked, so I am pretty well stumped.

I think this has to do with my less-than-sufficient knowledge of Linux.


Kindest regards,

Larry



Eiffel Studio "about" info:

Installation information:
Version = EiffelStudio 20.11 (20.11.10.5048 - linux-x86-64)
Monitor DPI = 96

$ISE_EIFFEL = /home/larry/eiffel/Eiffel_20.11
$ISE_LIBRARY = /home/larry/eiffel/Eiffel_20.11

r...@amalasoft.com

unread,
Mar 15, 2021, 8:14:18 AM3/15/21
to eiffel...@googlegroups.com
Hi Larry

Not a solution, just a reminder:  While U and I are the only vowels need in Linux (orig. Unix), most issues in that environment stem from the 3 Ps:  path, permission and process.  The first of those is the most common, especially when flying semi-blind a la the process route.

R

Larry Rix

unread,
Mar 15, 2021, 8:56:03 AM3/15/21
to Eiffel Users
Thanks, rfo!

MORE INFO: I went back to the eiffel.org post and rediscovered that there are examples. I opened the examples, compiled and ran them, only to discover that the examples are working, but silently.

In Linux, I have to run Eiffel Studio from a command prompt to see stdio outputs. So, I did so with the examples. This worked, much to my amusement! So, back to my code.

I copy and paste in the "simple" example code and get nothing for my trouble in the stdio. I do the same thing with the http_post example in my code. It works in the example project, but fails in mine to produce the same stdio dump in the call to "perform".

So, something like you say (path, permission, process) is off the rails.

Larry Rix

unread,
Mar 15, 2021, 9:19:11 AM3/15/21
to Eiffel Users
MORE INFO: So, I put the example in the APPLICATION class for my test target and then finalized. Move the finalized binary to the project root. Went to the root in the terminal and ran it.

WORKS PERFECTLY!!!

SO—that BEGS the question—how do I get output out of cURL other than the stupid stdio???? I want to grab what comes back from a curl-call out to a server into a STRING variable and work with it.

Ulrich Windl

unread,
Mar 15, 2021, 9:31:05 AM3/15/21
to eiffel...@googlegroups.com
>>> Larry Rix <lar...@moonshotsoftware.com> schrieb am 15.03.2021 um 13:01 in
Nachricht <e6f42f84-7a84-4ec5...@googlegroups.com>:
> Good morning all!
>
> I am unsure what other details would be helpful to you all or to me for
> that matter.
>
> However—I can tell you the following:
>
> - I am on Linux Mint, which I think is a standard Debian distro (I think

> I have that right).
> - Typing "curl -v" at the command prompt tells me that curl is installed

> on my OS.
> - I am using Eiffel Studio 20.11 with the cURL library installed in the
> $ISE_LIBRARY folder.
>
> I read my own notes on the Easy Curl Example page on eiffel.org, but those
> notes are for Windows, so I am unsure as to how they work or apply in a
> Linux distro.
>
> What I can tell you is that I have the library listed in the ECF file.
>
> Of further interest (and most likely unrelated) is that I even tried to
> "shell out" using the process and base_process libraries to see if I could
> get a call out to the shell and run cURL from the command line. This fails
> to work at any level, which really surprises me. Doing the shell-execute
> thing in Windows has always worked, so I am pretty well stumped.
>
> I think this has to do with my less-than-sufficient knowledge of Linux.

Hi!

Could it be 32-bit vs. 64-bit? You need one library for each architecture.
On A SUSE (SLES) system:
# zypper search libcurl
S | Name | Summary | Type
--+----------------+----------------------------------+--------
i | libcurl4 | Version 4 of cURL shared library | package
| libcurl4-32bit | Version 4 of cURL shared library | package

Regards,
Ulrich
https://groups.google.com/d/msgid/eiffel-users/e6f42f84-7a84-4ec5-8f1a-e1b49a

> 49a49en%40googlegroups.com.



Ulrich Windl

unread,
Mar 15, 2021, 9:34:24 AM3/15/21
to eiffel...@googlegroups.com
>>> Larry Rix <lar...@moonshotsoftware.com> schrieb am 15.03.2021 um 13:56 in
Nachricht <0d872a58-48f6-46ae...@googlegroups.com>:
> Thanks, rfo!
>
> MORE INFO: I went back to the eiffel.org post and rediscovered that there
> are examples. I opened the examples, compiled and ran them, only to
> discover that the examples are working, but silently.
>
> In Linux, I have to run Eiffel Studio from a command prompt to see stdio
> outputs. So, I did so with the examples. This worked, much to my amusement!

> So, back to my code.
>
> I copy and paste in the "simple" example code and get nothing for my
> trouble in the stdio. I do the same thing with the http_post example in my
> code. It works in the example project, but fails in mine to produce the
> same stdio dump in the call to "perform".
>
> So, something like you say (path, permission, process) is off the rails.

When going to the library or system level, ltrace and strace might be your
friends.
As a beginer's example you might try "ltrace date" and "strace date". For
longer output you probably want to redirect it to a file of filter the events
being logged...

>
> On Monday, March 15, 2021 at 8:14:18 AM UTC-4 rfo wrote:
>
>> Hi Larry
>>
>> Not a solution, just a reminder: While U and I are the only vowels need
>> in Linux (orig. Unix), most issues in that environment stem from the 3 Ps:

>> path, permission and process. The first of those is the most common,
>> especially when flying semi-blind a la the process route.
>>
>> R
>>
>> -------- Original Message --------
>> Subject: Re: [EXT] [eiffel-users] cURL Library on Linux
>> From: Larry Rix <lar...@moonshotsoftware.com>
>> Date: Mon, March 15, 2021 8:01 am
>> To: Eiffel Users <eiffel...@googlegroups.com>
>>
>> Good morning all!
>>
>> I am unsure what other details would be helpful to you all or to me for
>> that matter.
>>
>> However—I can tell you the following:
>>
>> - I am on Linux Mint, which I think is a standard Debian distro (I
>> think I have that right).
>> - Typing "curl -v" at the command prompt tells me that curl is
>> installed on my OS.
>> - I am using Eiffel Studio 20.11 with the cURL library installed in
<https://groups.google.com/d/msgid/eiffel-users/e6f42f84-7a84-4ec5-8f1a-e1b49a

> 49a49en%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Eiffel Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to eiffel-users...@googlegroups.com.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/eiffel-users/0d872a58-48f6-46ae-8d58-1026bb

> 732460n%40googlegroups.com.



Ulrich Windl

unread,
Mar 15, 2021, 9:40:05 AM3/15/21
to eiffel...@googlegroups.com
>>> Larry Rix <lar...@moonshotsoftware.com> schrieb am 15.03.2021 um 14:19 in
Nachricht <fa9f6ca0-51be-4dcf...@googlegroups.com>:
> MORE INFO: So, I put the example in the APPLICATION class for my test
> target and then finalized. Move the finalized binary to the project root.
> Went to the root in the terminal and ran it.
>
> WORKS PERFECTLY!!!
>
> SO—that BEGS the question—how do I get output out of cURL other than the
> stupid stdio???? I want to grab what comes back from a curl-call out to a
> server into a STRING variable and work with it.

Now are you using the "curl" command, or are you using the curl library? My
guess is that the library outputs neither stdout nor stderr.

I did not use curl, but here's some Perl code I found; maybe it leads you in
the right direction:
use WWW::Curl::Easy;

my $curl = WWW::Curl::Easy->new;

$curl->setopt(CURLOPT_HEADER,1);
$curl->setopt(CURLOPT_URL, 'http://example.com');

# A filehandle, reference to a scalar or reference to a
typeglob can be used here.
my $response_body;
$curl->setopt(CURLOPT_WRITEDATA,\$response_body);

# Starts the actual request
my $retcode = $curl->perform;

# Looking at the results...
if ($retcode == 0) {
print("Transfer went ok\n");
my $response_code =
$curl->getinfo(CURLINFO_HTTP_CODE);
# judge result and next action based on $response_code
print("Received response: $response_body\n");
} else {
# Error code, type of error, error message
print("An error happened: $retcode
".$curl->strerror($retcode)." ".$curl->errbuf."\n");
}

Regards,
Ulrich
>>> - I am on Linux Mint, which I think is a standard Debian distro (I
>>> think I have that right).
>>> - Typing "curl -v" at the command prompt tells me that curl is
>>> installed on my OS.
>>> - I am using Eiffel Studio 20.11 with the cURL library installed in
> --
> You received this message because you are subscribed to the Google Groups
> "Eiffel Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to eiffel-users...@googlegroups.com.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/eiffel-users/fa9f6ca0-51be-4dcf-b10f-c24674

> 399c2bn%40googlegroups.com.



r...@amalasoft.com

unread,
Mar 15, 2021, 10:07:22 AM3/15/21
to eiffel...@googlegroups.com
Hi Larry

Many years ago, ....

Here's a snippet from one of my classes I have used to execute external commands and capture the output.
It uses PROCESS and related classes
R


run_external_command_with_timeout (
    cl: STRING; d: detachable STRING; cb: PROCEDURE [STRING]; tmo: INTEGER)
    -- Execute an external command line and capture its exit status
    -- and output (if any)
  require
    command_exists: cl /= Void and then not cl.is_empty
    valid_timeout: tmo >= 0    -- 0 denotes use default
    -- working directory 'd' is optional
    -- Agent (callback) 'cb' is optional
  local
    pf: PROCESS_FACTORY
    tx: PROCESS
    tov: INTEGER
  do
    if tmo = 0 then
      tov := 60_000
    else
      tov := tmo
    end
    create pf
    tx := pf.process_launcher_with_command_line (cl, d)
    last_xcmd := tx
    if cb /= Void then
      tx.redirect_output_to_agent (cb)
    end
    tx.set_on_fail_launch_handler (agent on_failed_launch)
    tx.launch
    --tx.wait_for_exit
    if tx.launched then
      tx.wait_for_exit_with_timeout (tov)
    end
  end
 
-------- Original Message --------
Subject: Re: [EXT] [eiffel-users] cURL Library on Linux
From: Larry Rix <lar...@moonshotsoftware.com>
Date: Mon, March 15, 2021 9:19 am
To: Eiffel Users <eiffel...@googlegroups.com>

MORE INFO: So, I put the example in the APPLICATION class for my test target and then finalized. Move the finalized binary to the project root. Went to the root in the terminal and ran it.

WORKS PERFECTLY!!!

SO—that BEGS the question—how do I get output out of cURL other than the stupid stdio???? I want to grab what comes back from a curl-call out to a server into a STRING variable and work with it.


On Monday, March 15, 2021 at 8:56:03 AM UTC-4 Larry Rix wrote:
Thanks, rfo!

MORE INFO: I went back to the eiffel.org post and rediscovered that there are examples. I opened the examples, compiled and ran them, only to discover that the examples are working, but silently.

In Linux, I have to run Eiffel Studio from a command prompt to see stdio outputs. So, I did so with the examples. This worked, much to my amusement! So, back to my code.

I copy and paste in the "simple" example code and get nothing for my trouble in the stdio. I do the same thing with the http_post example in my code. It works in the example project, but fails in mine to produce the same stdio dump in the call to "perform".

So, something like you say (path, permission, process) is off the rails.

On Monday, March 15, 2021 at 8:14:18 AM UTC-4 rfo wrote:
Hi Larry

Not a solution, just a reminder:  While U and I are the only vowels need in Linux (orig. Unix), most issues in that environment stem from the 3 Ps:  path, permission and process.  The first of those is the most common, especially when flying semi-blind a la the process route.

R

-------- Original Message --------
Subject: Re: [EXT] [eiffel-users] cURL Library on Linux
From: Larry Rix <lar...@moonshotsoftware.com>
Date: Mon, March 15, 2021 8:01 am
To: Eiffel Users <eiffel...@googlegroups.com>

Good morning all!

I am unsure what other details would be helpful to you all or to me for that matter.

However—I can tell you the following:
  • I am on Linux Mint, which I think is a standard Debian distro (I think I have that right).
  • Typing "curl -v" at the command prompt tells me that curl is installed on my OS.

--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.

Larry Rix

unread,
Mar 16, 2021, 5:58:14 AM3/16/21
to Eiffel Users
So, it turns out that instead of a silent-fail, I have a silent-success.

The code is "working", but I was not aware of how to "see it working". Jocelyn pointed out to me the "get_in_memory" example, which allows me to put what the server sends back (JSON in this case) into a simple STRING variable.

l_curl_string: CURL_STRING
...
curl_easy.setopt_integer (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_writedata, l_curl_string.object_id)

It's this call with "writedata" and something to "write-into" that fills the l_curl_string with the cURL response data stream.

My only remaining question is with the setting of post options.

I am making a call on my IBM Cloud account for Speech-to-Text (e.g. sending an MP3 or FLAC binary and getting AI-generated JSON back). The CLI cURL in Linux looks like:

curl -X POST -u "apikey:{apikey}" \
--header "Content-Type: audio/flac" \
--data-binary @{path_to_file}audio-file.flac \
"{url}/v1/recognize?timestamps=true&max_alternatives=1"

When I send this at the command prompt, it works great. I get precisely what I ask for.

When I attempt to send it through the cURL library, I get: {"code":401, "error": "Unauthorized"}

The code is:

    fetch_transcript_json (a_file: PATH; a_ext: STRING)
            -- Fetch JSON transcript from IBM server.
        local
            l_result: INTEGER
            l_curl_string: CURL_STRING
            l_options: STRING
            l_creds: TT_CREDS
        do
            create l_creds
            create l_curl_string.make_empty
            l_options := options.twin
            l_options.replace_substring_all ("<<APIKEY>>", l_creds.api_key)
            l_options.replace_substring_all ("<<AUDIO_EXT>>", a_ext)
            l_options.replace_substring_all ("<<FILE_SPEC>>", a_file.name.out)
            l_options.replace_substring_all ("<<URL>>", l_creds.url)

            check has_api: curl_easy.is_api_available then
                curl_handle := curl_easy.init

                    -- First we specify which URL we would like to download.
                curl_easy.setopt_string (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_url, l_creds.url)
                curl_easy.setopt_string (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_postfields, l_options)

                    -- Send all data to default Eiffel curl write function
                curl_easy.set_write_function (curl_handle)

                    -- We pass our `l_curl_string''s object id to the callback function */
                curl_easy.setopt_integer (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_writedata, l_curl_string.object_id)

                    -- After `perform' has been called, the remote HTML source is printed in the console.
                l_result := curl_easy.perform (curl_handle)

                    -- Always cleanup
                curl_easy.cleanup (curl_handle)

                last_json := l_curl_string.out
            end
        end

    last_json: detachable STRING

feature {NONE} -- Constants

    options: STRING = "[
-X POST -u "<<APIKEY>>>" --header "Content-Type: audio/<<AUDIO_EXT>>" --data-binary @<<FILE_SPEC>> "<<URL>>"
]"

Larry Rix

unread,
Mar 17, 2021, 10:06:42 AM3/17/21
to Eiffel Users
The reality is—I still do not see how to pass CLI options using code like this. It doesn't appear to work.
Reply all
Reply to author
Forward
0 new messages