From nobody Fri Jun 09 01:21:53 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 4Qcjww5H8Kz4cFhN for ; Fri, 9 Jun 2023 01:22:08 +0000 (UTC) (envelope-from aryeh.friedman@gmail.com) Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) (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 4Qcjww3cv0z3rkN for ; Fri, 9 Jun 2023 01:22:08 +0000 (UTC) (envelope-from aryeh.friedman@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-977e0fbd742so190659166b.2 for ; Thu, 08 Jun 2023 18:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686273726; x=1688865726; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=afJGaMsA9qDRJoFVGmghcvO6C8CEtm5LoNTjYmNPbRc=; b=T4/G31zvZ5iBgIi9jenmNKk8iAbwF7lO6+3YVUyw2c3LnRIxZoxlXpG6gHcMM4QM9U WXxSIbbEYyI3BC7HJ759OgxmhsYpMZfjPshdBMnKDS4FftWw+/CaIcCOL1q/dbfPk84y XN6iNJu45W0RISxnJe7XEjjgBWTrBl/3mYiTJDvEgT8NTpfHeFqeJXHl6qqBB+iLz5JT i8cTSKt5051Qalw+uRbQ9uMeGCih7WsdcjueQCS9/liA+hu2zIhiJqS5iWTVkePwisCe EA1I2M1VHusEJZBmA2ppBD+tG6cKjW+uFDzbsJOk39TJaD+0Sa7rbKumAKBPR4UtXBLx t4RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686273726; x=1688865726; h=content-transfer-encoding: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=afJGaMsA9qDRJoFVGmghcvO6C8CEtm5LoNTjYmNPbRc=; b=QgHEwzGibniNX3bVLgfco+KTn1VsFhL3m5ievs5OjBZ8t2A1jonJo/5Z152DqLotC2 Ny67C7dzw96uOiStKNmM211mzY9aOxLSylqd+MUVdIMxwVQkmLToEucrAMqDwF/dnoyL 1iSZn2xqc5vpkRXMu/b4EoVBakS/SddREpxbwyVwN4/y9rUhG4f7zYuXTiW8x5K9wdyw BKyewwt5S97XVi8/6PI6Z+vCmoYt8ThtAl2QkRJ9QU0MbVbnGn9AzXVFmgfOUAz1e2ec A3SRRmoY8unUrwLE+reBuoANk8oJBPs0DVzGsNBWOw3yyl06Un2Na1mZbqAeuWPbxT0X Srug== X-Gm-Message-State: AC+VfDyvIkYyXx4Nda9+Hm50XMbUc/FkCWhDmoavjaAJSctf/WJ/COni oW70CljGFdse+0Mbzop9fqGCXo/AQWUcmoOD/KAXj7uA+mI= X-Google-Smtp-Source: ACHHUZ4fbrucbfovU5ZXeHCNQBMLAVylMOXDFZolXEfTMuyOhDIYTR9yKQPs4wkxWGnbujEduLKttUwvrHCzGeQ/shI= X-Received: by 2002:a17:906:d54f:b0:973:d80f:ea69 with SMTP id cr15-20020a170906d54f00b00973d80fea69mr194054ejc.29.1686273725548; Thu, 08 Jun 2023 18:22:05 -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: <202306090036.42118.dr.klepp@gmx.at> From: Aryeh Friedman Date: Thu, 8 Jun 2023 21:21:53 -0400 Message-ID: Subject: Re: Slightly OT: non-buffered stdin in Java To: "Dr. Nikolaus Klepp" Cc: questions@freebsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 4Qcjww3cv0z3rkN X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; TAGGED_FROM(0.00)[]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N 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 was > > > > wondering if there is a command that will make stdin go to a file s= o > > > > 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" disable= s linebuffer on input by itself, so you should use someting else for testin= g. > > 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 % --=20 Aryeh M. Friedman, Lead Developer, http://www.PetiteCloud.org