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

Reply via email to