 : join-arguments ( args -- cmd-line )
     [ escape-argument ] map " " join ;
 
-: app-name/cmd-line ( -- app-name cmd-line )
-    +command+ get [
+: app-name/cmd-line ( process -- app-name cmd-line )
+    command>> dup string? [
         " " split1
     ] [
-        +arguments+ get unclip swap join-arguments
-    ] if* ;
+        unclip swap join-arguments
+    ] if ;
 
-: cmd-line ( -- cmd-line )
-    +command+ get [ +arguments+ get join-arguments ] unless* ;
+: cmd-line ( process -- cmd-line )
+    command>> dup string? [ join-arguments ] unless ;
 
-: fill-lpApplicationName
-    app-name/cmd-line
-    pick set-CreateProcess-args-lpCommandLine
-    over set-CreateProcess-args-lpApplicationName ;
+: fill-lpApplicationName ( process args -- process args )
+    over app-name/cmd-line
+    >r >>lpApplicationName
+    r> >>lpCommandLine ;
 
-: fill-lpCommandLine
-    cmd-line over set-CreateProcess-args-lpCommandLine ;
+: fill-lpCommandLine ( process args -- process args )
+    over cmd-line >>lpCommandLine ;
 
-: fill-dwCreateFlags
+: fill-dwCreateFlags ( process args -- process args )
     0
-    pass-environment? [ CREATE_UNICODE_ENVIRONMENT bitor ] when
-    +detached+ get winnt? and [ DETACHED_PROCESS bitor ] when
-    over set-CreateProcess-args-dwCreateFlags ;
+    over pass-environment? [ CREATE_UNICODE_ENVIRONMENT bitor ] when
+    over detached>> winnt? and [ DETACHED_PROCESS bitor ] when
+    >>dwCreateFlags ;
 
-: fill-lpEnvironment
-    pass-environment? [
+: fill-lpEnvironment ( process args -- process args )
+    over pass-environment? [
         [
-            get-environment
+            over get-environment
             [ "=" swap 3append string>u16-alien % ] assoc-each
             "\0" %
         ] { } make >c-ushort-array
-        over set-CreateProcess-args-lpEnvironment
+        >>lpEnvironment
     ] when ;
 
-: fill-startup-info
-    dup CreateProcess-args-lpStartupInfo
+: fill-startup-info ( process args -- process args )
+    dup lpStartupInfo>>
     STARTF_USESTDHANDLES swap set-STARTUPINFO-dwFlags ;
 
-HOOK: fill-redirection io-backend ( args -- args )
+HOOK: fill-redirection io-backend ( process args -- process args )
 
 M: windows-ce-io fill-redirection ;
 
-: make-CreateProcess-args ( -- args )
+: make-CreateProcess-args ( process -- args )
     default-CreateProcess-args
     wince? [ fill-lpApplicationName ] [ fill-lpCommandLine ] if
     fill-dwCreateFlags
     fill-lpEnvironment
-    fill-startup-info ;
+    fill-startup-info
+    nip ;
 
 M: windows-io current-process-handle ( -- handle )
     GetCurrentProcessId ;

io.streams.duplex windows.types math windows.kernel32 windows
namespaces io.launcher kernel sequences windows.errors assocs
splitting system threads init strings combinators
io.backend ;
IN: io.windows.launcher

TUPLE: CreateProcess-args

            make-CreateProcess-args
            fill-redirection
            dup call-CreateProcess
            CreateProcess-args-lpProcessInformation
        ] with-descriptor
    ] with-destructors ;

