From nobody Fri Jun 9 02:32:14 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 4QclV556CYz4bDLF for ; Fri, 9 Jun 2023 02:32:29 +0000 (UTC) (envelope-from pprocacci@gmail.com) Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) (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 4QclV42GKYz43BC for ; Fri, 9 Jun 2023 02:32:28 +0000 (UTC) (envelope-from pprocacci@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20221208 header.b=iceyBiLy; spf=pass (mx1.freebsd.org: domain of pprocacci@gmail.com designates 2607:f8b0:4864:20::c31 as permitted sender) smtp.mailfrom=pprocacci@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-558b04141e2so901712eaf.0 for ; Thu, 08 Jun 2023 19:32:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686277946; x=1688869946; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=SENwznYnk1CFERSWf5xrFg1FsEsmGiK5nnV1inotFaI=; b=iceyBiLykc4RzvCcoCOpQvnfmTOKBSCA/DfehPV8pbI3Wy4YHtvtu+E+QTKIXlpvmK Q/dAOe34PKimm8NZP+XByan9StjEh2BswlU9Mq7LbmNGI3br87N4gQJQor/XV/4ECIU1 gOcYC6nR6k+ny12ZESdyOqY33nzhCKrd/YTN/Rq5AzPMUxE7BEEOeSJn5AqaeeAX1Cv4 wsw6KEI/Ag6ab21EXhjlxrab41uVfj4nsWBSVTTzXzHa1WtP9C1wIMvfyME6BXJTtldH jOSoO6Edi/+9Visa+QYWJQlY0jH5mgxxvnwtUE8wBSGSoSSMNZJPj6e/U00xIBmNpTdX ZtAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686277946; x=1688869946; 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=SENwznYnk1CFERSWf5xrFg1FsEsmGiK5nnV1inotFaI=; b=LtFNRqF9vIyJkNhw6d9HXBjvwfvmQoDhaG/+rORD0QdUxbNfrh9uzMJr7Nx7EJq+ji uIj7ODRt8x/tJVeQKEtjG03tUnjajkfcYRqvdWHMtyOQpxpUeXCr5FUuqm5CQy/G285T ewhnoQnhAbV8evr67ebugmGCVN6Iv3u6gGOSuQptEIQvDaAePtb5wzKyuwH73Ja8Okym p1T65/0HejopyQFm+VeTB9sDAUIhZWR8g+VwgHW/DfiJr7ECKuXJHcG6A7runopDMcs+ FVzjamYT70V6wfXCzyeN+/eUffqhdOpzcGwijQHreCohDY48HazMayK9aBdzauUjjmN3 653A== X-Gm-Message-State: AC+VfDyo/tYC2VUTAlnki9joST1mLHL3yFUXfvPYaJgz4dBrZu2P5mzr 2JL24z2PNctcWPleLrQ1ocbiwaacMhe5ufvcOA== X-Google-Smtp-Source: ACHHUZ5hfJBCM1e04ParELVTVinLp92KZNgS8CXLgGTd20RF5hammQr/HbxR/ZD5kuoDRxAXZMZ/7GZyUVfAdCUhT8I= X-Received: by 2002:a4a:c44b:0:b0:558:b4cb:b18a with SMTP id h11-20020a4ac44b000000b00558b4cbb18amr1098153ooq.6.1686277946117; Thu, 08 Jun 2023 19:32:26 -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 22:32:14 -0400 Message-ID: Subject: Re: Slightly OT: non-buffered stdin in Java To: Aryeh Friedman Cc: "Dr. Nikolaus Klepp" , questions@freebsd.org Content-Type: multipart/alternative; boundary="000000000000f8923f05fda92dec" X-Spamd-Result: default: False [-3.99 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.99)[-0.993]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20221208]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TAGGED_RCPT(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; BLOCKLISTDE_FAIL(0.00)[2607:f8b0:4864:20::c31:server fail]; PREVIOUSLY_DELIVERED(0.00)[questions@freebsd.org]; MLMMJ_DEST(0.00)[questions@freebsd.org]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::c31:from]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; DKIM_TRACE(0.00)[gmail.com:+]; FREEMAIL_TO(0.00)[gmail.com]; MID_RHS_MATCH_FROMTLD(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; FREEMAIL_CC(0.00)[gmx.at,freebsd.org]; 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]; RCVD_COUNT_TWO(0.00)[2] X-Rspamd-Queue-Id: 4QclV42GKYz43BC X-Spamd-Bar: --- X-ThisMailContainsUnwantedMimeParts: N --000000000000f8923f05fda92dec Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jun 8, 2023 at 9:22=E2=80=AFPM Aryeh Friedman 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 > 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 from > > > > > files/sockets and other generic InputStreams unbuffered. So I w= as > > > > > 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 fil= e > > > > > 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. ~Paul --=20 __________________ :(){ :|:& };: --000000000000f8923f05fda92dec Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Thu, Jun 8, 2023 at 9:22=E2= =80=AFPM Aryeh Friedman <ary= eh.friedman@gmail.com> wrote:
On Thu, Jun 8, 2023 at 6:37=E2=80=AFPM Dr. Nikolaus Kl= epp <dr.klepp@gmx.a= t> 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. Nikolaus Klepp <dr.klepp@gmx.at> w= rote:
> > >
> > > Anno domini 2023 Thu, 8 Jun 14:01:19 -0400
> > >=C2=A0 Aryeh Friedman scripsit:
> > > > Under Java stdin (System.in) is a buffered stream not s= ent to the
> > > > application until return is pressed.=C2=A0 But, Java ca= n read from
> > > > files/sockets and other generic InputStreams 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 ->file but that m= akes it hard to
> > > > sync stdout and stderr (both are unbuffered in Java) wi= th 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 s= ometing else for testing.
>
> Nik
>

I am pretty convinced by the following test it is not working as advertised= :

aryehl@neomarx:~/Desktop % cat foo.c
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

int main()
{
=C2=A0 =C2=A0 int in=3Dfcntl(STDIN_FILENO, F_DUPFD, 0);
=C2=A0 =C2=A0 int out=3Dfcntl(STDOUT_FILENO, F_DUPFD, 0);
=C2=A0 =C2=A0 char c=3D0;

=C2=A0 =C2=A0 do {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 read(in,&c,1);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 write(out,&c,1);
=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.PetiteCloud.org


stdbuf only works for stdio buffering of which read(= 2) and write(2) aren't.

~Paul

--
__________________

:(){ :|:& };:
--000000000000f8923f05fda92dec--