• Check process gives exactly one line with exactly one integer back

    From Cecil Westerhof@21:1/5 to All on Sat Jan 1 04:26:02 2022
    I am going to get the output from a process with a 'open "! command"'.
    What is the best way to check it returns exactly one line that
    contains nothing else as one integer (beside white-space)?

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Gollwitzer@21:1/5 to All on Sat Jan 1 10:50:38 2022
    Am 01.01.22 um 04:26 schrieb Cecil Westerhof:
    I am going to get the output from a process with a 'open "! command"'.
    What is the best way to check it returns exactly one line that
    contains nothing else as one integer (beside white-space)?


    string is integer $result

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cecil Westerhof@21:1/5 to Christian Gollwitzer on Sat Jan 1 13:57:03 2022
    Christian Gollwitzer <auriocus@gmx.de> writes:

    Am 01.01.22 um 04:26 schrieb Cecil Westerhof:
    I am going to get the output from a process with a 'open "! command"'.
    What is the best way to check it returns exactly one line that
    contains nothing else as one integer (beside white-space)?


    string is integer $result

    It is so very simple. ;-)

    This does accept the case where there is one or more empty lines (with white-space), but that is in my case not a problem.

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alan Grunwald@21:1/5 to Cecil Westerhof on Sun Jan 2 12:05:15 2022
    On 01/01/2022 12:57, Cecil Westerhof wrote:
    Christian Gollwitzer <auriocus@gmx.de> writes:

    Am 01.01.22 um 04:26 schrieb Cecil Westerhof:
    I am going to get the output from a process with a 'open "! command"'.
    What is the best way to check it returns exactly one line that
    contains nothing else as one integer (beside white-space)?


    string is integer $result

    It is so very simple. ;-)

    This does accept the case where there is one or more empty lines (with white-space), but that is in my case not a problem.

    string is -strict integer $result

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Gollwitzer@21:1/5 to All on Sun Jan 2 14:56:34 2022
    Am 02.01.22 um 14:28 schrieb Cecil Westerhof:
    Alan Grunwald <nospam.nurdglaw@gmail.com> writes:

    On 01/01/2022 12:57, Cecil Westerhof wrote:
    Christian Gollwitzer <auriocus@gmx.de> writes:

    Am 01.01.22 um 04:26 schrieb Cecil Westerhof:
    I am going to get the output from a process with a 'open "! command"'. >>>>> What is the best way to check it returns exactly one line that
    contains nothing else as one integer (beside white-space)?


    string is integer $result
    It is so very simple. ;-)
    This does accept the case where there is one or more empty lines (with
    white-space), but that is in my case not a problem.

    string is -strict integer $result

    Nope:
    $ puts ${result}
    1234


    $ string is integer -strict ${result}
    1


    The difference is:

    (demo) 58 % string is integer -strict ""
    0
    (demo) 59 % string is integer ""
    1

    Christian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cecil Westerhof@21:1/5 to Alan Grunwald on Sun Jan 2 14:28:33 2022
    Alan Grunwald <nospam.nurdglaw@gmail.com> writes:

    On 01/01/2022 12:57, Cecil Westerhof wrote:
    Christian Gollwitzer <auriocus@gmx.de> writes:

    Am 01.01.22 um 04:26 schrieb Cecil Westerhof:
    I am going to get the output from a process with a 'open "! command"'. >>>> What is the best way to check it returns exactly one line that
    contains nothing else as one integer (beside white-space)?


    string is integer $result
    It is so very simple. ;-)
    This does accept the case where there is one or more empty lines (with
    white-space), but that is in my case not a problem.

    string is -strict integer $result

    Nope:
    $ puts ${result}
    1234


    $ string is integer -strict ${result}
    1

    But for my current situation it is certainly not a showstopper.

    And when it becomes a showstopper I can use:
    llength [split ${result} \n

    and check it returns 1.


    In case it will not be visible:
    - the first line contains ' 1234 '
    - the two lines beyond that contain ' '

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cecil Westerhof@21:1/5 to Christian Gollwitzer on Sun Jan 2 15:38:58 2022
    Christian Gollwitzer <auriocus@gmx.de> writes:

    Am 02.01.22 um 14:28 schrieb Cecil Westerhof:
    Alan Grunwald <nospam.nurdglaw@gmail.com> writes:

    On 01/01/2022 12:57, Cecil Westerhof wrote:
    Christian Gollwitzer <auriocus@gmx.de> writes:

    Am 01.01.22 um 04:26 schrieb Cecil Westerhof:
    I am going to get the output from a process with a 'open "! command"'. >>>>>> What is the best way to check it returns exactly one line that
    contains nothing else as one integer (beside white-space)?


    string is integer $result
    It is so very simple. ;-)
    This does accept the case where there is one or more empty lines (with >>>> white-space), but that is in my case not a problem.

    string is -strict integer $result
    Nope:
    $ puts ${result}
    1234

    $ string is integer -strict ${result}
    1


    The difference is:

    (demo) 58 % string is integer -strict ""
    0
    (demo) 59 % string is integer ""
    1

    Aah, thanks. So I should always use strict and when I want to be sure
    there is only one line I should us split and llength.

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From heinrichmartin@21:1/5 to Cecil Westerhof on Mon Jan 3 02:11:50 2022
    On Sunday, January 2, 2022 at 3:44:19 PM UTC+1, Cecil Westerhof wrote:
    Aah, thanks. So I should always use strict and when I want to be sure
    there is only one line I should us split and llength.

    regexp {^\d+$}

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cecil Westerhof@21:1/5 to heinrichmartin on Mon Jan 3 14:04:16 2022
    heinrichmartin <martin.heinrich@frequentis.com> writes:

    On Sunday, January 2, 2022 at 3:44:19 PM UTC+1, Cecil Westerhof wrote:
    Aah, thanks. So I should always use strict and when I want to be sure
    there is only one line I should us split and llength.

    regexp {^\d+$}

    Almost: it should be:
    regexp {^[ \t]*\d+[ \t]*$}

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)