From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!tr1.eu1.usenetexpress.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!buffer1.nntp.dca1.giganews.com!buffer2.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 03 Apr 2020 20:48:35 -0500 From: Dennis Lee Bieber Newsgroups: comp.lang.ada Subject: Re: Running a simple Python from Ada program Date: Fri, 03 Apr 2020 21:48:36 -0400 Organization: IISS Elusive Unicorn Message-ID: References: User-Agent: ForteAgent/8.00.32.1272 X-No-Archive: YES MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-nBpT8468XfQAavR8Z34FZhD1+tfrN55C5FS65B7krUtjn7lO1HpfG8dak0rdL4iX0ZnpDDnwHVlr/xt!ehehNNMBtmgbSuSa9I069fqP0zmdhdmL+PDhswkQk3irvb5IppzSu5XdWsR5t1xaf2gJRhMH X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2929 Xref: reader01.eternal-september.org comp.lang.ada:58307 Date: 2020-04-03T21:48:36-04:00 List-Id: On Fri, 3 Apr 2020 12:19:44 -0700 (PDT), "Rego, P." declaimed the following: > >So I will try to simplify a bit the question. I want to do the equivalent of this > > #include > #include > 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/