On Tue, Aug 3, 2021 at 1:13 PM George Neuner <gneun...@comcast.net> wrote:
>
>
> On 8/3/2021 1:03 PM, Norman Gray wrote:
> > On 3 Aug 2021, at 17:38, George Neuner wrote:
> >
> >> Racket is multi-platform and tries to present a common API for
> >> dealing with underlying operating systems.  Windows is an important
> >> platform, but Windows does not have the concept of fork/exec ... so
> >> Racket doesn't offer it either.
> >
> > Ah: good point.  That said, I'd have guessed that similar behaviour --
> > 'invoke and don't return' -- would be at least emulatable on Windows,
> > though.
>
> Well, yes, but the behavior of  'CreateProcess'  is quite different from
> the combination of  'forkv/execv'.
>
> In Windows, the new child is not (even virtually) a copy of its parent -
> it is a completely new process context.  Although it is possible for the
> parent to pass to and/or share resources with the child, this doesn't
> include a copy of its memory context [so no 'fork'].  The parent
> receives several handles to the new child process that must explicitly
> be closed in order to detach it.
>
> As a technical matter, emulating Unix 'fork' in Windows ... i.e. making
> an independent copy of the parent process that continues running from
> where the parent stopped ... is possible, but it is difficult and
> requires debugger like behavior to manipulate the child's memory map and
> copy data from one process to the other.
>
>
> >> The closest (and simplest) you can achieve, I think, would to start
> >> Vi asynchronously using 'process*' and then terminate the Racket script.
> >
> > I don't think that works, since terminating the Racket process would
> > also terminate its child (unless I were to do something similar to the
> > usual extra fork to disconnect the child from its parent, and... hmmm,
> > this isn't sounding very rackety).
> >
> > Doing the next simplest thing -- using (process* "/usr/bin/vi"
> > '("foo")) and calling (control 'wait) using the result -- doesn't seem
> > to work, but instead just hangs, until I kill the vi child process.
> > Without digging into it too deeply, I'd guess that's because of the
> > usual problems about wiring up FDs and buffers and so on, which I was
> > rather hoping to avoid.
> >
>
> Hmm.  According to the docs  'process'  (no asterisk) executes the
> command asynchronously ... I assumed  'process*' would do the same.
> Unfortunately 'process' returns ports that must be closed explicitly.
>
> Sorry if I led you astray.
>

I tried directly passing the current input port and the current output
port in Racket to the subprocess. As long as they are the original
standard input and the standard output ports, the program seems to
work.

*However*, I am not sure if Racket's runtime still manages the input
and the output.

#lang racket/base

(require racket/match
         racket/system)

(match-define (list subprocess-stdout subprocess-stdin system-pid
subprocess-stderr procctl)
  (process*/ports (current-output-port) (current-input-port)
(current-error-port)
                  "/usr/bin/vim"))

(procctl 'wait)

The following variant prevents Racket from terminating the spawn
subprocess. Sadly, it did not work when I changed sh to vim. The error
message from vim was 'Vim: Error reading input, exiting...'.

#lang racket/base

(require racket/match
         racket/system)

(match-define (list subprocess-stdout subprocess-stdin system-pid
subprocess-stderr procctl)
  (parameterize ([current-subprocess-custodian-mode #f])
    (process*/ports (current-output-port) (current-input-port)
(current-error-port)
                    "/bin/sh"
                    "-c"
                    "echo sh sleeping; sleep 5; echo sh alive and well")))

(displayln "leave racket")



>
> > Best wishes,
> >
> > Norman
>
> George
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/720fc753-7972-b8c1-76ec-4d2a65a763f2%40comcast.net.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BYdHfw718MkhW7MRTtgSyKZ1rgPrWZD%2B47bXS%2B2JGzFLQ%40mail.gmail.com.

Reply via email to