From nobody Fri Jun 09 02:55:32 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 4Qcm0x3K06z4bHCc; Fri, 9 Jun 2023 02:55:45 +0000 (UTC) (envelope-from aryeh.friedman@gmail.com) Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (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 4Qcm0x1TMBz45cw; Fri, 9 Jun 2023 02:55:45 +0000 (UTC) (envelope-from aryeh.friedman@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-97460240863so234128666b.0; Thu, 08 Jun 2023 19:55:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686279344; x=1688871344; 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=YqdfKGq0fjJ4+5OOjUKlAz5dgOrGRlIJhhPfIBYgh0I=; b=YQMRxb08Gy3jDjLPbU26CG9Lak+LwfamNPPKBoxZW/Aj70CSQ7LvVlBSK0Igpst3wL lVHm7RTKEXmmdon6kepk6uCBJjbuazyv332TRvsWIniWUIFhwW1J6/pq77/gW9znKvkG wcFsVJ+oGCg1ZUftJZPO2Aw8MB1X1O5MPFVCPoRvLbv2OGezGq0cdEbthd4VCdICrVEI b7ONawJrFKMfQBwhDF8IuVi+9uuxB12X3AsLCtalzd4FzPM8ce/gNQXYUsGVlSHVRY0d ogNGvLcSAy5IqrfbpoO+ZB8iHGINqZx8hZResPjvWtwW4ZwjkDvStvpJEWBSKssPzgL9 frHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686279344; x=1688871344; 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=YqdfKGq0fjJ4+5OOjUKlAz5dgOrGRlIJhhPfIBYgh0I=; b=HrwfhN62Ne1eY9RkZ6HBbm9Fdej0sNoFArxAqyHmHSTDdGDmxa/hej0YCESO8LFx+y vwuZjzmkf5ct+OITFrxdpc5sp++irdW9iQjCpCpDqm4tlf0yIXyyTq2VT4z5ArVAKHs4 lW3IGgkt4177pomdbmYvG1wJdkIzQOsBxIZd1j3HxoyTUp5Mz5YA4cixssTN7k75B8pL uusrhdLJjRgsMMjc39y2l5BiQnMM9hBisTCeC327I91jJa6cZzK827c4eddesUd1DXL2 Tqxvsc4pqW1LeSz7ORIafiRwvDFPaFxe5lIQMpxG2cIqg2lvzEAfkuvEpZckMmqa1+vp veJw== X-Gm-Message-State: AC+VfDxK1YMHdjYt6GvxaOMu4qEveeGzXX870E1jhayFrkefZCz4gbho CbI7Y3tIavPJMrkpOgHdNgzJxREBJnFDzBZULPHPVUeH X-Google-Smtp-Source: ACHHUZ7lWJzDwwRko2+mjcwFSvkj72e6HKqVfkFe6GlEfWj7K248M3eQbnuPOkyHm5s6CUj+inps+oqL+A8F9Uk9M+Q= X-Received: by 2002:a17:907:168f:b0:94f:449e:75db with SMTP id hc15-20020a170907168f00b0094f449e75dbmr572703ejc.52.1686279343462; Thu, 08 Jun 2023 19:55:43 -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: Aryeh Friedman Date: Thu, 8 Jun 2023 22:55:32 -0400 Message-ID: Subject: Re: Slightly OT: non-buffered stdin in Java To: Paul Procacci Cc: "Dr. Nikolaus Klepp" , questions@freebsd.org, freebsd-java@freebsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 4Qcm0x1TMBz45cw X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; TAGGED_FROM(0.00)[] 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 10:32=E2=80=AFPM Paul Procacci = wrote: > > > > 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 th= e >> > > > > 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 fil= e 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 fi= le >> > > > > 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" disa= bles linebuffer on input by itself, so you should use someting else for tes= ting. >> > >> > Nik >> > >> >> I am pretty convinced by the following test it is not working as adverti= sed: >> >> 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. --=20 Aryeh M. Friedman, Lead Developer, http://www.PetiteCloud.org