Bill, thank you, this certainly helps. It looks like that 1!:* expect a FILE* ptr for plain files and fd-s for files associated with processes. I thought may be the family supports both, but apparently this is not the case:
danil@dalu:~/L/j64-805$ ./jconsole.sh '' fwrite <'test.txt' 0 (1!:21) <'test.txt' 11284256 'FILE* handle' (1!:3) 11284256 'libc.so.6 fileno > i x'&cd 11284256 4 ' fd handle' (1!:3) 4 |file number error | ' fd handle' (1!:3)4 ' just set fd handle' (1!:2) 4 just set fd handle just set fd handle I assume, in the past fd-s were used as inputs for 1!:* and then for some reason decided to switch to FILE* instead, but were not 2!:* changed accordingly? It is strange, that it somehow even works in you example, given that the same foreign consumes different file handle types. regards, Danil regards, Danil 2017-04-05 18:17 GMT+03:00 bill lam <[email protected]>: > 2!:2 had broken for a very long time, the numbers returned > are file pointer (FILE*) not file descriptor. The following can > give some sensible output, but still incomplete. > > fread=: 1!:1 > fwrite=: 1!:2 > run=: 4 : 0 > echo 'p fi fo'=. 2!:2 x > echo i=. 'libc.so.6 fileno > i x'&cd fi > echo o=. 'libc.so.6 fileno > i x'&cd fo > y fwrite i NB. Write to its input > z=.fread o NB. Read its output > z NB. Result > ) > > now running: > '/bin/cat' run 'dog' > 3872 93921913337728 93921913453968 > 4 > 7 > dog > > > Ср, 05 апр 2017, Danil Osipchuk написал(а): > > Greetings, everyone > > > > I'm not able to appy (2!:2). I wonder if it is working as intended - the > > results I get are confusing. > > > > Two sources of documentation are available: > > > > Dictionary entry suggests it should return a list of (pid stdin stdout), > in > > that order. > > > > 2!:2 y Host IO. (Unix only.) The host command line y is passed to /bin/sh > > for processing, connecting two file numbers to the command’s standard > input > > and output. The result is a 3-element list of the process id of the task > > started and the file numbers associated with its standard input and > output. > > These file numbers also appear in the result of 1!:20 . In this case, > > instead of appearing with a name they appear with the command line, > > prefixed by > (standard input) or < (standard output). The files > associated > > with the process should be closed with 1!:22 when no longer in use. See > > also 2!:3 for a verb to wait for processes to complete. > > > > Example from user guide http://www.jsoftware.com/help/ > user/stdin_stdout.htm > > implies a different order of (pid stdout stdin): > > > > run=: 4 : 0 > > 'p o i'=. 2!:2 x NB. Run command, save Process, Output, Input > > y fwrite i NB. Write to its input > > fclose i NB. Close its input > > 2!:3 p NB. Wait for process to terminate > > z=.fread o NB. Read its output > > fclose o NB. Close its output > > z NB. Result > > ) > > > > ==== > > > > Now in a console session: > > > > NB: version: > > > > 9!:14 '' > > j805/j64/linux/release/commercial/www.jsoftware.com/2016-12-11T08:02:52 > > > > NB. try to open cat in a hope to read a copy of what is being write into > > stdin > > (2!:2) '/bin/cat' > > 3166 26802912 26767136 > > > > NB. I would expect a small integers for stdin/stdout as file descriptors, > > but that is just expectation of course, may be this is something else > > > > NB. trying to append to stdin according to the description first: > > 'hey ther' (1!:3) 26802912 > > |file number error > > | 'hey ther' (1!:3)26802912 > > NB. now according the user guide: > > 'hey ther' (1!:3) 26767136 > > > > NB. looks like stdin is last in the list, append worked for it > > > > NB. trying to close stdin: > > > > (1!:22) 26767136 > > |domain error > > | (1!:26767136)26767136 > > > > > > NB. result of the attempt to close the stdin looks weird. > > > > NB. let us try to open existing file to find out how a descriptor should > > look like, because it used to be a small integer > > NB. 1!:21 y Open. Open file named y, creating it if necessary; result is > a > > file number. > > > > (1!:21) <'test.txt' > > asdf > > > > NB. contents of file returned instead of number? > > > > (1!:21) < 'nonexistent' > > |domain error > > | (1 !:'nonexistent')<'nonexistent' > > (1!:21) 'nonexistent' > > |ill-formed number > > > > NB. had to double check glass lenses and description for the file family > > foreigns > > NB. something wrong goes here - file foreigns look messed up at this > point > > > > ====== > > Just to check my own sanity in a fresh session file foreigns work fine of > > course: > > danil@dalu:~/L/j64-805$ ./jconsole.sh > > > > (1!:21) <'asdff.txt' > > 9980640 > > (1!:22) 9980640 > > 1 > > (1!:21) <'test.txt' > > 9944944 > > > > (1!:22) 9944944 > > 1 > > danil@dalu:~/L/j64-805$ > > > > regards, Danil > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > -- > regards, > ==================================================== > GPG key 1024D/4434BAB3 2008-08-24 > gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3 > gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3 > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
