Both the following issues have been previously noted by Bill Lam
A) "http://www.jsoftware.com/pipermail/programming/2009-June/015219.html"
B) "http://www.jsoftware.com/pipermail/programming/2009-March/014174.html"
A)
The Foreign conjunction 2!:1 does not behave as specified in the dictionary:
==============
2!:1 y
Spawn. (Unix only.) Like 2!:0, but yields '' without waiting for the host to
finish. Any output is ignored. For example, 2!:1 can be used to invoke a
text-editor.
==============
In fact 2!:1 does wait for the host to finish before continuing to process a
terminal session. There does not seem to be any difference in behaviour
between the following two commands.
2!:1 'gedit'
2!:0 'gedit'
Can this be fixed to behave as specified?
In the meantime here is a variation of Bill's suggested workaround:
fork=: [: 2!:1 '(' , ')&' ,~ ]
B)
There is a terminology conflict in the use of the name "spawn" between the
dictionary page "http://www.jsoftware.com/help/dictionary/dx002.htm" and the
task.ijs script (~system/packages/misc/task.ijs).
The dictionary suggests that "Spawn" has no I/O but task.ijs uses the name
"spawn" for tasks with I/O (and the verb "fork" for tasks with no I/O)
NB.*spawn v [monad] get stdout of executed task
NB. form: stdout=. spawn cmdline
It would be nice to resolve this conflict to reduce potential confusion.
Perhaps the easiest fix is to change the name of 2!:1 in the dictionary to
"fork". This won't affect any existing code, whereas changes to names of verbs
in task.ijs will.
In addition I notice that the verb hostcmd (or similar) is used in a number of
scripts for running commands on Unix.
hostcmd=: [: 2!:0 '(' , ] , ' || true)'"_
Perhaps with some minor changes to task.ijs cross-platform use of the verbs
fork, spawn, shell and launch can replace various handlings
* Leave the Windows implementations as they are.
* Change 1st line of definition of fork from
fork=: (3 : 0)`(2!:1)@.IFUNIX
to
fork=: (3 : 0)`([: 2!:1 '(' , ')&' ,~ ])@.IFUNIX
* Change 1st line of definition of spawn from
spawn=: (3 : 0)`(2!:0...@])@.IFUNIX
to
spawn=: (3 : 0)`([: 2!:1 '(' , ' || true)' ,~ ])@.IFUNIX
Discussion solicited!
An aside:
The behaviour of 2!:1 *appears* to vary depending on whether it is invoked from
jconsole or jwd.
When the following is invoked from jwd ...
2!:1 'hostname'
... the output is as specified.
However if the same command is invoked from jconsole ...
2!:1 'hostname'
ubuntu810vm
... it appears that a result is returned. Closer inspection reveals that result
of the foreign conjunction is in fact '' as specified, but that stdout is
written to the terminal session.
''-: 2!:1 'hostname'
ubuntu810vm
1
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm