comp.lang.ada
 help / color / mirror / Atom feed
From: Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject: Re: Running a simple Python from Ada program
Date: Fri, 03 Apr 2020 21:48:36 -0400
Date: 2020-04-03T21:48:36-04:00	[thread overview]
Message-ID: <udpf8ft2rbhm5e8jvjtnl7k1pkdsdisg0l@4ax.com> (raw)
In-Reply-To: e1993dba-8fa0-4dcf-85cb-63625c704fe6@googlegroups.com

On Fri, 3 Apr 2020 12:19:44 -0700 (PDT), "Rego, P." <pvrego@gmail.com>
declaimed the following:

>
>So I will try to simplify a bit the question. I want to do the equivalent of this
>
>    #include <stdio.h>
>    #include <stdlib.h>
>    int main(){
>      system("python testpy.py ddddd");
>      return 0;
>    }
>In this case it does not block the testpy.py printouts.
>
>But I am doing this
>    with Interfaces.C; use Interfaces.C;
>    procedure systest2 is
>       function Sys (Arg : Char_Array) return Integer;
>       pragma Import(C, Sys, "system");
>       Ret_Val : Integer;
>    begin
>       Ret_Val := Sys(To_C("python testpy.py arg1 arg2"));
>    end systest2;
>which blocks the testpy.py script until its end. This should not happen. So, please, how could I fix this?

	system() block until the invoked command completes... That happens for
both C and via the Ada definition.

	However, output via python print() might be getting buffered if the
spawned command does not see stdout as a console -- which might be a result
of not having the C I/O environment initialized...

	Try adding the -u option to the invocation
https://docs.python.org/3/using/cmdline.html#miscellaneous-options
"""
-u

    Force the stdout and stderr streams to be unbuffered. This option has
no effect on the stdin stream.

    See also PYTHONUNBUFFERED.

    Changed in version 3.7: The text layer of the stdout and stderr streams
now is unbuffered.
"""

EG: "python -u testpy.py arg1 arg2"


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

  parent reply	other threads:[~2020-04-04  1:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-03 16:57 Running a simple Python from Ada program Rego, P.
2020-04-03 17:35 ` Dmitry A. Kazakov
2020-04-03 19:05   ` Rego, P.
2020-04-03 19:19     ` Rego, P.
2020-04-03 20:06       ` Dmitry A. Kazakov
2020-04-04  1:48       ` Dennis Lee Bieber [this message]
2020-04-03 23:49   ` Mikhail Terekhov
2020-04-04  2:55     ` Nasser M. Abbasi
2020-04-04  8:15     ` Dmitry A. Kazakov
2020-04-04 10:44 ` fabien.chouteau
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox