3-JSON

(rgbcu.be)

Comments

veltas 25 July 2025
The environment variable isn't much better, both are akin to using a global var in your reentrant code, but at least STDDATA_FD is less likely to collide than 3.

Can't wait for scripts using this variable for something unrelated to break when they call my scripts.

This should be a parameter or argv[0]-based.

smarx007 25 July 2025
This is long overdue. PowerShell has long supported passing structured output (objects) via pipes and this is the closest attempt to approximate that without breaking the world.
mmastrac 25 July 2025
It's a shame that stdX streams were never spec'd as sockets, with appropriate handling available in the various shells.

Also, file handle inheritance by default was such a big mistake.

gerikson 25 July 2025
> Okay, apparently the stddata addition is causing havoc (who knew how many scripts just haphazardly hand programs random file descriptors, that's surely not a problem.)

I knew, and I've known since reading the "C shell considered harmful" paper, which offhandedly mentioned that sh-based shells can use an arbitrary number of file descriptors (maybe they have to be one-digit integers though). csh can't, of course.

It's discussed in the first section here

https://harmful.cat-v.org/software/csh

superdisk 25 July 2025
Tangential but I was surprised to see that tree(1), at least the popular implementation, is made in Terre Haute (which is where I'm from). Maybe I should invite the author for lunch or something :)
NoboruWataya 25 July 2025
I've never heard of stddata. What distro/environment provides it?
zbendefy 25 July 2025
offtopic: why is the Copyright © icon shake like crazy at the bottom of the page?

Edit: Oh I guess it seems to be intentional, I clicked around and I like the rgbcube site map.

Joker_vD 25 July 2025
> who knew how many scripts just haphazardly hand programs random file descriptors, that's surely not a problem.

Oh for fuck's sake! Why are you using random file descriptors nobody told you about? Those open fds are there for a reason, thank you: I've put an end of an open pipe specifically so I could notice when it will become closed.

If the user set up the environment of your application in a specific way, that means he wants your application to run in such an environment. If you were invoked with 10 non-standard file descriptors open and two injected threads — you'll have to live with it. Because, believe it or not, your application's purpose is to serve the user's goals. So don't break composability that the user relies on, please.

krick 21 hours ago
Can somebody explain what's going on here? It seems I'm missing some important piece of background info. Why don't they just add -J flag for everyone who wants to output JSON? Oh, wait, tree already has -J flag to output JSON. So WTF are they doing here?

I am especially confused by this:

> Surely, nothing will happen if I just assume that the existence of a specific file descriptor implies something, as nobody is crazy or stupid enough to hardcode such a thing?

Wait, what? But "you" (tree authors) just hardcoded such a thing. Do "you" have some special permission to do this nonsense?

EdSchouten 23 hours ago
If only there was a variant of execve() / posix_spawn() that simply took a literal array of which file descriptors would need to be present in the new process. So that you can say:

    int subprocess_stdin = open("/dev/null", O_RDONLY);
    int subprocess_stdout = open("some_output", O_WRONLY);
    int subprocess_stderr = STDERR_FILENO; // Let the subprocess use the same stderr as me.
    int subprocess_fds[] = {subprocess_stdin, subprocess_stdout, subprocess_stderr};
    posix_spawn_with_fds("my process", [...], subprocess_fds, 3);
Never understood why POSIX makes all of this so hard.
williamcotton 25 July 2025
For this the key would be to eliminate serialization and deserialization between steps in the pipeline.
fvwmuser 21 hours ago
I wouldn't have said this is anything new.

FreeBSD has libxo[0] integrated into some of its tools:

[0] https://github.com/Juniper/libxo

dodomodo 25 July 2025
every time I see the output of nushell I get so disappointed, they got the formatting so wrong, all the extra delimiters makes it hard to actually read the data. powershell got it right, using alignment. if you look at virtually all shell programs until the last few years you are going to see a similar, alignment based output. only recently, with the rise of the abuse of ligature, we started seeing this kind of incomprehensible blobs surrounding our text.
js8 23 hours ago
Why not use a saner protocol than JSON, e.g. CBOR?
cryptonector 18 hours ago
Sorry, but this is going to be very dangerous because much code will close unwanted FDs then open others. It's 50 years too late to add this convention.

Instead maybe we need new system calls that return dups of a hidden stddata FD or create/replace it.

crabbone 23 hours ago
The company I work for is guilty of abusing 3. We use it for debug output of user-supplied scripts that are meant to implement monitoring / metrics :'(

This is the first time I hear about stddata though. Is this a thing that's going into a standard? Is there already? Or is it just a name someone gave to it and it's not a real thing?