hostcmd_j_ solves it by putting the argument in parenthesis before handing it off to the shell interpreter.
Those parenthesis mean that their contents are handled in another process. So the redirects that J engine adds to the command line happen in the parent process and the redirects introduced by the J argument to hostcmd_j_ happen in the child process, and they both function. I am really tempted to try to rewrite that routine in xh.c, to make hostcmd_j_ unnecessary, but I would have to study it for a while to absorb the conventions it's using (or, ok, just move hostcmd_j_ into xh.c). FYI, -- Raul On Mon, Nov 27, 2017 at 12:51 AM, bill lam <[email protected]> wrote: > In j805 2!:0 always failed for this both on linux and mac, On j806, > change had been made on the linux branch but not on mac. The code > starts from line 42 of > the file xh.c > https://github.com/jsoftware/jsource/blob/master/jsrc/xh.c > > note the command passed to 2!:0 is appended with redirection for a tmp > file which is used to collect result to report to J. > > 'cmd .... ' > tmpfile > if the cmd itself already contains an output redirection such as what > you did, then there will be 2 output redirections in the resultant > cmd, > 'bla bla > fork,6 > tmpfile' > perhaps the shell interpreter used in system() is not smart enough to > handle it. > > What is the expected standard behavior for it? Why hostcmd_j_ can > solve it? I dun know. > > > > On Mon, Nov 27, 2017 at 1:07 PM, J. Patrick Harrington > <[email protected]> wrote: >> Many thanks. The expression >> hostcmd_j_ =: [: 2!:0 '(' , ,&' || true)' solves the problem I had with >> just 2!:0. But is there an explination >> why an exprssion of the form 2!:0 'foo.exe <infile >outfile' should >> work on some machines and fail on others, when both are running the >> same version of J? I'm afraid my grasp of unix scripting is too poor >> to understand just what hostcmd_j_ does. >> >> Patrick >> >> >> On Sat, 25 Nov 2017, Joey K Tuttle wrote: >>> >>> Chris, >>> Thanks for the credit - and I'm glad to see that hostcmd_j_ is commonly >>> available. >>> >>> But, to be fair, I plagiarized the definition from Martin Neitzel more >>> than 23 years ago... >>> >>> My servers invoke it many thousands of times a day in various monitoring >>> scripts - and I use it often in CLI sessions as well. >>> I like the fact that it always returns a result (as well as echoing stderr >>> output to my CLI session), which desire is what Martin responded to all >>> those years ago. >>> >>> - joey >>> >>> >>>> On 2017Nov 25, at 12:14, chris burke <[email protected]> wrote: >>>> >>>> hostcmd_j_ is Joey's cover for 2!:0, e.g. see >>>> www.jsoftware.com/pipermail/programming/2017-April/047204.html >>>> >>>> On Sat, Nov 25, 2017 at 12:06 PM, J. Patrick Harrington >>>> <[email protected]> >>>> wrote: >>>> >>>>> Sorry, I meant "returning with no screen output' >>>>> I am now running the full program with hostcmd_j_ for 2!:0. >>>>> It's chugging away, hasn't failed yet. :-) >>>>> >>>>> >>>>> On Sat, 25 Nov 2017, J. Patrick Harrington wrote: >>>>> >>>>>> Chris, >>>>>> >>>>>> That test works. I just tried >>>>>> >>>>>> hostcmd_j_ '../synmod.exe < fort.5 >fort.6' >>>>>> >>>>>> and that works as well, returning with screen output, and writing >>>>>> successfully to fort.6. So hostcmd_j_ ~: 2!:0 >>> >>> >>> ---------------------------------------------------------------------- >>> For information about J forums see http://www.jsoftware.com/forums.htm >> >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
