From nobody Fri Jun 09 03:37:39 2023 X-Original-To: questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QcmxY5t5qz4bN6V; Fri, 9 Jun 2023 03:37:53 +0000 (UTC) (envelope-from pprocacci@gmail.com) Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QcmxX5HC8z4Gww; Fri, 9 Jun 2023 03:37:52 +0000 (UTC) (envelope-from pprocacci@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20221208 header.b=RlhI1ht0; spf=pass (mx1.freebsd.org: domain of pprocacci@gmail.com designates 2607:f8b0:4864:20::329 as permitted sender) smtp.mailfrom=pprocacci@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-6b2c3ec38f0so235626a34.1; Thu, 08 Jun 2023 20:37:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686281871; x=1688873871; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ZTp/jT0JgKCdKwp/Q5Anrj2zYYQT2CEBFyVPU0aHV9U=; b=RlhI1ht0+R2JwG9tcCFApuReMe3mCKWYe3MxhzWZIij1QI0ESc/Z1EznP0lH4rHqUu jzXU+nHgqyh1S0K5lHeCUQHi4ACVVfPqbz8zt1Qx7Lpxd1/aJCkf1nm6JqTfyk2D0Ul4 hcSeiYEr4lKwFx41/IAlJ9ydla1HPbSBsm4GqF5xs2LDhqOz1Rqi5bQgyEHaHowyw5wo gCgLCBRKGcWA4ec+rqUFGnbxWcFPPFQKMJL/EAcHi3knyQswfsIlKhWZ48vG9rvMVyEl Ab12OYwJZDI1gvTKNiJ2NP5nZgMWTvflLdL4+kGewPO6MuvCaVbCXbDeq2cNF7egwked Q4FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686281871; x=1688873871; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZTp/jT0JgKCdKwp/Q5Anrj2zYYQT2CEBFyVPU0aHV9U=; b=QwyHIfx1zrTJ8hFgTP+OqqDPfbLzjNmcaMpw+nVIucaMqXyRM74sAaLFF7WtWzyVEB lO32sK/okzPWWc7mWeMa4KKU1NREDXVlEoIMJO37uIZ2vI6J4e18GmG8nqEUTOKnLqEg gcDO2TvhWkLvd6wVgwiE55txHvBbqcZl22srg8MapCDNl2diNJU+2wtZEmj9FICZ9/X2 W5z3aar3cJvQyM2FqievUqRrt58rJcNSLJqW3gfq20hj8QSy/+A1E2JMwzUnHIIIPMaa 37Uy72zKyZolbHNyc0mJLudODRyKTIDtv2h/U2GCsWmt3sQ8lI7weSLmgxiPzj/mMByf bhEw== X-Gm-Message-State: AC+VfDxywVLAYAgFoJ8jK5weJTLa9XDQ+JHEQk2w/BtzSm/w1apm8owt TsS/iGc9GeW32NTEeRRfQLpU7/Omq0RC/mROSg== X-Google-Smtp-Source: ACHHUZ6qIZnMeOr9JdepZyIWSgngAeijjf+bHzy5dz9Kcs+RlYDA5gSNH4kMtS0qDl6Lu4PpF3k10r/ihlYL05FPSuo= X-Received: by 2002:a05:6830:5a:b0:6b2:a9f0:9fc2 with SMTP id d26-20020a056830005a00b006b2a9f09fc2mr236545otp.10.1686281871489; Thu, 08 Jun 2023 20:37:51 -0700 (PDT) List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 References: <202306082039.36831.dr.klepp@gmx.at> <202306090036.42118.dr.klepp@gmx.at> In-Reply-To: From: Paul Procacci Date: Thu, 8 Jun 2023 23:37:39 -0400 Message-ID: Subject: Re: Slightly OT: non-buffered stdin in Java To: Aryeh Friedman Cc: "Dr. Nikolaus Klepp" , questions@freebsd.org, freebsd-java@freebsd.org Content-Type: multipart/alternative; boundary="000000000000f1007605fdaa17df" X-Spamd-Result: default: False [-2.50 / 15.00]; SUSPICIOUS_RECIPS(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.998]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20221208]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; FREEMAIL_CC(0.00)[gmx.at,freebsd.org]; MLMMJ_DEST(0.00)[questions@freebsd.org,freebsd-java@freebsd.org]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::329:from]; TAGGED_RCPT(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; RCVD_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[gmail.com:+]; FREEMAIL_TO(0.00)[gmail.com]; MID_RHS_MATCH_FROMTLD(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; ARC_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FREEMAIL_ENVFROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[] X-Rspamd-Queue-Id: 4QcmxX5HC8z4Gww X-Spamd-Bar: -- X-ThisMailContainsUnwantedMimeParts: N --000000000000f1007605fdaa17df Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jun 8, 2023 at 11:36=E2=80=AFPM Aryeh Friedman wrote: > On Thu, Jun 8, 2023 at 11:23=E2=80=AFPM Paul Procacci wrote: > > > > > > > > On Thu, Jun 8, 2023 at 10:55=E2=80=AFPM Aryeh Friedman > wrote: > >> > >> On Thu, Jun 8, 2023 at 10:32=E2=80=AFPM Paul Procacci > wrote: > >> > > >> > > >> > > >> > On Thu, Jun 8, 2023 at 9:22=E2=80=AFPM Aryeh Friedman < > aryeh.friedman@gmail.com> wrote: > >> >> > >> >> On Thu, Jun 8, 2023 at 6:37=E2=80=AFPM Dr. Nikolaus Klepp > wrote: > >> >> > > >> >> > Anno domini 2023 Thu, 8 Jun 17:22:38 -0400 > >> >> > Aryeh Friedman scripsit: > >> >> > > On Thu, Jun 8, 2023 at 2:39=E2=80=AFPM Dr. Nikolaus Klepp < > dr.klepp@gmx.at> wrote: > >> >> > > > > >> >> > > > Anno domini 2023 Thu, 8 Jun 14:01:19 -0400 > >> >> > > > Aryeh Friedman scripsit: > >> >> > > > > Under Java stdin (System.in) is a buffered stream not sent > to the > >> >> > > > > application until return is pressed. But, Java can read fr= om > >> >> > > > > files/sockets and other generic InputStreams unbuffered. > So I was > >> >> > > > > wondering if there is a command that will make stdin go to = a > file so > >> >> > > > > that Java can open that file and read it unbuffered? > >> >> > > > > > >> >> > > > > I know I can do something like cat ->file but that makes it > hard to > >> >> > > > > sync stdout and stderr (both are unbuffered in Java) with > the file > >> >> > > > > version of stdin > >> >> > > > > > >> >> > > > > >> >> > > > "stdbuf" might be what you look for: > >> >> > > > > >> >> > > > https://man.freebsd.org/cgi/man.cgi?query=3Dstdbuf > >> >> > > > >> >> > > Will likely need to play with it more but stdbuf -i 0 -o 0 cat > -|cat > >> >> > > didn't produce the expected immediate echo I still had to hit > return > >> >> > > > >> >> > > >> >> > Your console is linebuffered, so "cat" receives lines. IIRC "cat" > disables linebuffer on input by itself, so you should use someting else f= or > testing. > >> >> > > >> >> > Nik > >> >> > > >> >> > >> >> I am pretty convinced by the following test it is not working as > advertised: > >> >> > >> >> aryehl@neomarx:~/Desktop % cat foo.c > >> >> #include > >> >> #include > >> >> #include > >> >> > >> >> int main() > >> >> { > >> >> int in=3Dfcntl(STDIN_FILENO, F_DUPFD, 0); > >> >> int out=3Dfcntl(STDOUT_FILENO, F_DUPFD, 0); > >> >> char c=3D0; > >> >> > >> >> do { > >> >> read(in,&c,1); > >> >> write(out,&c,1); > >> >> } while(c!=3DEOF); > >> >> } > >> >> aryehl@neomarx:~/Desktop % !cc > >> >> cc foo.c > >> >> aryehl@neomarx:~/Desktop % stdbuf -i 0 -o 0 ./a.out > >> >> this is not echoing! > >> >> this is not echoing! > >> >> neither is this > >> >> neither is this > >> >> ^C > >> >> aryehl@neomarx:~/Desktop % > >> >> > >> >> -- > >> >> Aryeh M. Friedman, Lead Developer, http://www.PetiteCloud.org > >> >> > >> > > >> > stdbuf only works for stdio buffering of which read(2) and write(2) > aren't. > >> > >> I also tried it with System.in.read() in Java and it was also buffered > >> but according to the openjdk source it appears that this is on > >> purpose. > >> > >> > >> > >> -- > >> Aryeh M. Friedman, Lead Developer, http://www.PetiteCloud.org > > > > > > > > When you just `./a.out` you're being bitten by the tty. > > You can manipulate that terminal to do what you want. Start reading > termios(4). > > > > Without a tty you will only get a character at a time with the followin= g: > > > > #include > > > > int main(int argc, char **argv) > > { > > char ch; > > for(;;){ > > ssize_t r =3D read(0,&ch,1); > > if(!r) break; > > write(1, &ch, 1); > > } > > _exit(0); > > } > > Please see the whole context the goal is to make it so I can type at > the command line into a java program and have instantaneous > presentation of any characters I enter to Java > > > > -- > Aryeh M. Friedman, Lead Developer, http://www.PetiteCloud.org > So take what I said and apply it to java. A quick google search: https://github.com/nyholku/purejavacomm/blob/master/src/jtermios/Termios.ja= va ~Paul --=20 __________________ :(){ :|:& };: --000000000000f1007605fdaa17df Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Thu, Jun 8, 2023 at 11:36=E2= =80=AFPM Aryeh Friedman <ary= eh.friedman@gmail.com> wrote:
On Thu, Jun 8, 2023 at 11:23=E2=80=AFPM Paul Procacci = <pprocacci@gmai= l.com> wrote:
>
>
>
> On Thu, Jun 8, 2023 at 10:55=E2=80=AFPM Aryeh Friedman <aryeh.friedman@gmail.com= > wrote:
>>
>> On Thu, Jun 8, 2023 at 10:32=E2=80=AFPM Paul Procacci <pprocacci@gmail.com&g= t; wrote:
>> >
>> >
>> >
>> > On Thu, Jun 8, 2023 at 9:22=E2=80=AFPM Aryeh Friedman <aryeh.friedman@g= mail.com> wrote:
>> >>
>> >> On Thu, Jun 8, 2023 at 6:37=E2=80=AFPM Dr. Nikolaus Klepp= <dr.klepp@gmx.at> wrote:
>> >> >
>> >> > Anno domini 2023 Thu, 8 Jun 17:22:38 -0400
>> >> >=C2=A0 Aryeh Friedman scripsit:
>> >> > > On Thu, Jun 8, 2023 at 2:39=E2=80=AFPM Dr. Niko= laus Klepp <
dr.klep= p@gmx.at> wrote:
>> >> > > >
>> >> > > > Anno domini 2023 Thu, 8 Jun 14:01:19 -0400=
>> >> > > >=C2=A0 Aryeh Friedman scripsit:
>> >> > > > > Under Java stdin (System.in) is a buf= fered stream not sent to the
>> >> > > > > application until return is pressed.= =C2=A0 But, Java can read from
>> >> > > > > files/sockets and other generic Input= Streams unbuffered.=C2=A0 =C2=A0So I was
>> >> > > > > wondering if there is a command that = will make stdin go to a file so
>> >> > > > > that Java can open that file and read= it unbuffered?
>> >> > > > >
>> >> > > > > I know I can do something like cat -&= gt;file but that makes it hard to
>> >> > > > > sync stdout and stderr (both are unbu= ffered in Java) with the file
>> >> > > > > version of stdin
>> >> > > > >
>> >> > > >
>> >> > > > "stdbuf" might be what you look = for:
>> >> > > >
>> >> > > > https://man.freeb= sd.org/cgi/man.cgi?query=3Dstdbuf
>> >> > >
>> >> > > Will likely need to play with it more but stdbu= f -i 0 -o 0 cat -|cat
>> >> > > didn't produce the expected immediate echo = I still had to hit return
>> >> > >
>> >> >
>> >> > Your console is linebuffered, so "cat" rec= eives lines. IIRC "cat" disables linebuffer on input by itself, s= o you should use someting else for testing.
>> >> >
>> >> > Nik
>> >> >
>> >>
>> >> I am pretty convinced by the following test it is not wor= king as advertised:
>> >>
>> >> aryehl@neomarx:~/Desktop % cat foo.c
>> >> #include <stdio.h>
>> >> #include <fcntl.h>
>> >> #include <unistd.h>
>> >>
>> >> int main()
>> >> {
>> >>=C2=A0 =C2=A0 =C2=A0int in=3Dfcntl(STDIN_FILENO, F_DUPFD, = 0);
>> >>=C2=A0 =C2=A0 =C2=A0int out=3Dfcntl(STDOUT_FILENO, F_DUPFD= , 0);
>> >>=C2=A0 =C2=A0 =C2=A0char c=3D0;
>> >>
>> >>=C2=A0 =C2=A0 =C2=A0do {
>> >>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0read(in,&c,1);
>> >>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0write(out,&c,1);
>> >>=C2=A0 =C2=A0 =C2=A0} while(c!=3DEOF);
>> >> }
>> >> aryehl@neomarx:~/Desktop % !cc
>> >> cc foo.c
>> >> aryehl@neomarx:~/Desktop % stdbuf -i 0 -o 0 ./a.out
>> >> this is not echoing!
>> >> this is not echoing!
>> >> neither is this
>> >> neither is this
>> >> ^C
>> >> aryehl@neomarx:~/Desktop %
>> >>
>> >> --
>> >> Aryeh M. Friedman, Lead Developer, http://www.PetiteClou= d.org
>> >>
>> >
>> > stdbuf only works for stdio buffering of which read(2) and wr= ite(2) aren't.
>>
>> I also tried it with System.in.read() in Java and it was also buff= ered
>> but according to the openjdk source it appears that this is on
>> purpose.
>>
>>
>>
>> --
>> Aryeh M. Friedman, Lead Developer, http://www.PetiteCloud.org=
>
>
>
> When you just `./a.out` you're being bitten by the tty.
> You can manipulate that terminal to do what you want.=C2=A0 Start read= ing termios(4).
>
> Without a tty you will only get a character at a time with the followi= ng:
>
> #include <unistd.h>
>
> int main(int argc, char **argv)
> {
>=C2=A0 =C2=A0char ch;
>=C2=A0 =C2=A0for(;;){
>=C2=A0 =C2=A0 =C2=A0ssize_t r =3D read(0,&ch,1);
>=C2=A0 =C2=A0 =C2=A0if(!r) break;
>=C2=A0 =C2=A0 =C2=A0write(1, &ch, 1);
>=C2=A0 =C2=A0}
>=C2=A0 =C2=A0_exit(0);
> }

Please see the whole context the goal is to make it so I can type at
the command line into a java program and have instantaneous
presentation of any characters I enter to Java



--
Aryeh M. Friedman, Lead Developer, http://www.PetiteCloud.org


So take what I said and= apply it to java.

A quick google search:

~Paul
--
__________________

:(){ :|:& = };:
--000000000000f1007605fdaa17df--