[Gllug] Changing destination of shell output

Nix nix at esperi.demon.co.uk
Thu Oct 24 23:34:28 UTC 2002


On 23 Oct 2002, Paul Roberts stated:
> Rhys Hopkins <rhys.hopkins at culver-tec.com> writes:
> 
>> Does anyone know if it is possible to change redirected output from a
>> background or stopped job to another file descriptor ?

No, it's not possible without installing an indirection layer in the way
in advance. (PTYs are good for this, as is the `socat' program, which
it seems can redirect *anything*. Unfortunately it has a grotesque
syntax and overwhelming docs.)

> I think The /proc filesystem is your friend here. I haven't done this
> personally, so my main aim is to point you in the right direction.

You can *look* at the fds via /proc, but you can't point them somewhere
else. The problem is that an fd ismore than /proc shows you it is; it's
also got a read/write state and a file position associated with it,
and there's no way to point all of that to another file without
closing the descriptor and reopening it (which the program would notice
and which only the program has any way to do in any case --- that'd also
break things if the descriptor was shared by other processes, as can be
done by fork() or fd-passing over Unix-domain sockets).

The way to redirect them is to stick something in the way that you can
instruct to point elsewhere (like socat, or a socat derivative rather
since I don't think you can tell socat to point itself elsewhere after
you've started it either...)

> As you can see, these are symlinks to the files I gave it as input /

Well, they're representations of the file descriptors, in the form of
a symlink. This isn't all the information encoded in the descriptor.

-- 
`The tooth fairy teaches children that they can sell body parts for money.'
                       --- David Richerby

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list