This is something I sent to the beta list but is now relevant to this one
since J7 has officially been released.  I had thought that a "fork" command
failed to spin off an independent process but it appears I was mistaken.

It looks like there really is no problem with "fork" other than it may not
give a prompt when it spins off a process, but it may  return a prompt when
the process ends.  So, if we do something like the following to create a
process script:

   (0 : 0) fwrite exefl=. 'C:/amisc/J/testFork.ijs'
1!:44 'C:/Program Files/J701/bin/'
load 'DHMConfig.ijs'
IsFORKED=: 1   NB. No welcome prompt if forked process...
load 'C:/amisc/Jsys/user/config/startup.ijs'
load 'filefns'
coinsert 'fldir'
qts=: ":@:(6!:0)
1!:44 'C:/amisc/J/'
(LF,~'Process forked at ',qts '') fwrite 'Forked.out'
6!:3]10  NB. Wait 10 seconds....
(LF,~'Process done at ','.',~qts '') fappend 'Forked.out'
)

Then define the executable thusly:

   JEXE=: '"C:/Program Files/j701/bin/jconsole" '

We can fork the process like this:

   fork JEXE,'C:/amisc/J/testFork.ijs'

Where I get no prompt until I press "Enter".  While I'm waiting, I check the
time a few times:

   qts''
2011 2 15 15 51 31.553
   qts''
2011 2 15 15 51 36.193
      qts''
2011 2 15 15 51 40.224

Notice how the last input has a double prompt, one of which is apparently
due to the forked process ending.  We can see that the first two entries
above happened while the process was running and the third one after it
finished by comparing these times to those in our output file:

   fread 'Forked.out'
Process forked at 2011 2 15 15 51 29.021
Process done at 2011 2 15 15 51 39.021.

I was afraid this implied that the forked process affects the parent forker,
but adding " 2!:55 '' " at the end of the process file causes it to exit
without killing the parent process and without an extra prompt.  Evidently
the extra prompt is due to my failure to terminate the child process within
the script.

However, I'm still not clear on how adding the termination also fixes the
lack-of-prompt problem: the version with the termination returns a prompt
immediately after forking the process.

On Thu, Dec 30, 2010 at 10:32 AM, Devon McCormick <[email protected]>wrote:

> All -
>
> I've recently gotten accustomed, in J6, to writing a few lines of code
> which will run for a long time to a file, then running these lines by
> forking off a non-display (console-less) version of J, e.g.
>
>    (0 : 0) fwrite 'bkpUsu.ijs'
> load 'bkp'     NB. Start custom backup: gather info on all files and dirs:
> 'FLNMS FLDTS FLSZS FLPARENT DIRNMS DIRDEP'=. PllDirInfoEG 'C:\'
>    NB. Save these results since they took so long to gather:
> (<'/Temp/')
> fileVar_WS_&.>'FLNMS';'FLDTS';'FLSZS';'FLPARENT';'DIRNMS';'DIRDEP'
>    NB. Use this information to copy most recent 10MB to dated dir:
> 'batfl cmds'=. buildBatFl_parseDir_ 10e6;'C:/Temp/NWMM20101230/'
> shell batfl
> 2!:55 ''
> )
>
>    JEXE=: 'C:\Program Files\J602\bin\J.exe'
>    fork ('"',JEXE,'" -jijx '),'bkpUsu.ijs'
>
> Unfortunately, J7 seems to provide no such option, at least that I can see,
> for spinning off an independent copy of the interpreter without tying up my
> current session.
> When I tried the above using
>    JEXE=: '"C:\Program Files\J701\bin\j7console" '
> the forked process runs in my existing console window (and using the
> "-jijx" option returns an error, as one might expect).
>
> Thanks,
>
> Devon
>
> Is there an easy way to spin off an independent copy of J in J7?
>
> --
> Devon McCormick, CFA
> ^me^ at acm.
> org is my
> preferred e-mail
>
>


-- 
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to