Posts: 4,646
Threads: 1,493
Joined: Sep 2016
Jan-14-2017, 10:13 AM
(This post was last modified: Jan-14-2017, 10:13 AM by Skaperen.)
this will be run in linux. i have a function that reads from and writes to
file descriptors ... the things that are used by os.read() and os.write(). i want this function to read from stdin and write to stdout. the problem is that the function
returns two file descriptors that it created, one to write to, and one to read from (they happen to be pipes like from os.pipe()). how can i get this function to read from stdin and write to stdout?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
the function is reading from and writing to ...
file descriptors ... as if it is doing
os.read() and
/or
os.write(). but it
makes the file descriptors (
like perhaps 6 and 7) and
returns them (so this is
not a case of simply passing 0 and 1 to the function). so i think i have set up some kind of concurrent descriptor-to-descriptor or sys.stdin-to-descriptor or descriptor-to-sys.stdout copying, like maybe launch 2 more child processes. that is, unless they is some other form of connecting file descriptors. i do know that C does not have such. but C wouldn't as it is a low layer just short of assembly and machine code.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
Jan-15-2017, 05:52 AM
(This post was last modified: Jan-15-2017, 06:04 AM by Skaperen.)
so, let's say i have a file descriptor and it is an int with the value of 14. now what?
this is not about how to "wrap" a file descriptor as sys.stdin or sys.stdout or such. if the function returns fd 17 for output then i could read from it to get the functions output but what if i want that data to go out on stdout? what if it willbe reading fd 15 and i want to have read stdin (to get the data fed to my script as stdin)?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
Jan-15-2017, 09:18 AM
(This post was last modified: Jan-15-2017, 09:18 AM by Skaperen.)
these fd things are basically a index into a pointer list of open files each process has. unix system layer thing. very early versions of unix had fun when programs did (in C) stuff like
write(12345,"x",1). of course, now days, there is a solid check of fd validity.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.