Index: /trunk/src/kash/main.c
===================================================================
--- /trunk/src/kash/main.c	(revision 2293)
+++ /trunk/src/kash/main.c	(revision 2294)
@@ -134,5 +134,5 @@
 		return 2;
 	shthread_set_shell(psh);
-	return shell_main(psh, argc, argv);
+	return shell_main(psh, argc, psh->argptr);
 }
 
Index: /trunk/src/kash/shfile.c
===================================================================
--- /trunk/src/kash/shfile.c	(revision 2293)
+++ /trunk/src/kash/shfile.c	(revision 2294)
@@ -381,5 +381,5 @@
         if (getcwd(buf, sizeof(buf)))
         {
-            pfdtab->cwd = strdup(buf);
+            pfdtab->cwd = sh_strdup(NULL, buf);
             if (!inherit)
             {
@@ -466,4 +466,5 @@
 
     shmtx_enter(&pfdtab->mtx, &tmp);
+    TRACE2((NULL, "shfile_fork_win:\n"));
 
     i = pfdtab->size;
@@ -473,5 +474,10 @@
         {
             HANDLE hFile = (HANDLE)pfdtab->tab[i].native;
-            DWORD  fFlag = set || !pfdtab->tab[i].cloexec ? HANDLE_FLAG_INHERIT : 0;
+            DWORD  fFlag = (set || !pfdtab->tab[i].cloexec)
+                         ? HANDLE_FLAG_INHERIT : 0;
+            if (set)
+                TRACE2((NULL, "  #%d: native=%#x flags=%#x cloexec=%d fFlag=%#x\n",
+                        i, pfdtab->tab[i].flags, hFile, pfdtab->tab[i].cloexec, fFlag));
+
             if (!SetHandleInformation(hFile, HANDLE_FLAG_INHERIT, fFlag))
             {
@@ -613,16 +619,80 @@
 int shfile_pipe(shfdtab *pfdtab, int fds[2])
 {
-#ifdef SH_PURE_STUB_MODE
-    return -1;
+    int rc;
+    int s;
+#ifdef SHFILE_IN_USE
+# if K_OS == K_OS_WINDOWS
+    HANDLE hRead  = INVALID_HANDLE_VALUE;
+    HANDLE hWrite = INVALID_HANDLE_VALUE;
+    SECURITY_ATTRIBUTES SecurityAttributes;
+
+    SecurityAttributes.nLength = sizeof(SecurityAttributes);
+    SecurityAttributes.lpSecurityDescriptor = NULL;
+    SecurityAttributes.bInheritHandle = TRUE;
+
+    if (!CreatePipe(&hRead, &hWrite, &SecurityAttributes, 4096))
+    {
+        fds[0] = shfile_insert(pfdtab, (intptr_t)hRead, O_RDONLY, -1, "shfile_pipe");
+        if (fds[0] != -1)
+        {
+            fds[1] = shfile_insert(pfdtab, (intptr_t)hWrite, O_WRONLY, -1, "shfile_pipe");
+            if (fds[1] != -1)
+                rc = 0;
+        }
+
+# else
+    int native_fds[2];
+    if (!pipe(native_fds))
+    {
+        fds[1] = -1;
+        fds[0] = shfile_insert(pfdtab, native_fds[0], O_RDONLY, -1, "shfile_pipe");
+        if (fds[0] != -1)
+        {
+            fds[1] = shfile_insert(pfdtab, native_fds[1], O_WRONLY, -1, "shfile_pipe");
+            if (fds[1] != -1)
+                rc = 0;
+        }
+# endif
+        s = errno;
+        if (fds[1] == -1)
+        {
+            if (fds[0] != -1)
+            {
+                shmtxtmp tmp;
+                shmtx_enter(&pfdtab->mtx, &tmp);
+                rc = fds[0];
+                pfdtab->tab[rc].fd = -1;
+                pfdtab->tab[rc].flags = 0;
+                pfdtab->tab[rc].native = -1;
+                shmtx_leave(&pfdtab->mtx, &tmp);
+            }
+
+# if K_OS == K_OS_WINDOWS
+            CloseHandle(hRead);
+            CloseHandle(hWrite);
+# else
+            close(native_fds[0]);
+            close(native_fds[1]);
+# endif
+            fds[0] = fds[1] = -1;
+            errno = s;
+            rc = -1;
+        }
+    }
+
+#elif defined(SH_PURE_STUB_MODE)
+    rc = -1;
+    errno = ENOSYS;
 
 #elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
 # ifdef _MSC_VER
-    return _pipe(fds, PIPE_BUF, O_BINARY);
-# else
-    return pipe(fds);
-# endif
-
-#else
-#endif
+    rc = _pipe(fds, PIPE_BUF, O_BINARY);
+# else
+    rc = pipe(fds);
+# endif
+#endif
+
+    TRACE2((NULL, "shfile_pipe() -> %d{%d,%d} [%d]\n", rc, fds[0], fds[1], errno));
+    return rc;
 }
 
Index: /trunk/src/kash/shforkA-win.asm
===================================================================
--- /trunk/src/kash/shforkA-win.asm	(revision 2293)
+++ /trunk/src/kash/shforkA-win.asm	(revision 2294)
@@ -107,4 +107,5 @@
         mov     [rax - 10h], r10
         mov     [rax - 18h], r11
+int3
         cmp     rax, r10
         jb      .below
Index: /trunk/src/kash/shinstance.c
===================================================================
--- /trunk/src/kash/shinstance.c	(revision 2293)
+++ /trunk/src/kash/shinstance.c	(revision 2294)
@@ -181,11 +181,12 @@
 
 /**
- * Clones an environment vector.
+ * Clones a string vector like enviorn or argv.
  *
  * @returns 0 on success, -1 and errno on failure.
+ * @param   psh     The shell to associate the allocations with.
  * @param   dstp    Where to store the clone.
  * @param   src     The vector to be cloned.
  */
-static int sh_env_clone(char ***dstp, char **src)
+static int sh_clone_string_vector(shinstance *psh, char ***dstp, char **src)
 {
    char **dst;
@@ -198,5 +199,5 @@
 
    /* alloc clone array. */
-   *dstp = dst = sh_malloc(NULL, sizeof(*dst) * items + 1);
+   *dstp = dst = sh_malloc(psh, sizeof(*dst) * items + 1);
    if (!dst)
        return -1;
@@ -206,11 +207,11 @@
    while (items-- > 0)
    {
-       dst[items] = sh_strdup(NULL, src[items]);
+       dst[items] = sh_strdup(psh, src[items]);
        if (!dst[items])
        {
            /* allocation error, clean up. */
            while (dst[++items])
-               sh_free(NULL, dst[items]);
-           sh_free(NULL, dst);
+               sh_free(psh, dst[items]);
+           sh_free(psh, dst);
            errno = ENOMEM;
            return -1;
@@ -246,5 +247,6 @@
 
         /* Call the basic initializers. */
-        if (    !sh_env_clone(&psh->shenviron, envp)
+        if (    !sh_clone_string_vector(psh, &psh->shenviron, envp)
+            &&  !sh_clone_string_vector(psh, &psh->argptr, argv)
             &&  !shfile_init(&psh->fdtab, inherit ? &inherit->fdtab : NULL))
         {
@@ -916,4 +918,8 @@
 #elif K_OS == K_OS_WINDOWS //&& defined(SH_FORKED_MODE)
     pid = shfork_do_it(psh);
+# ifdef DEBUG
+    if (!pid)
+        opentrace(psh);
+# endif
 
 #elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
@@ -928,4 +934,12 @@
 
 #endif
+
+    /* child: update the pid */
+    if (!pid)
+# ifdef _MSC_VER
+        psh->pid = _getpid();
+# else
+        psh->pid = getpid();
+# endif
 
     TRACE2((psh, "sh_fork -> %d [%d]\n", pid, errno));
Index: /trunk/src/kash/var.c
===================================================================
--- /trunk/src/kash/var.c	(revision 2293)
+++ /trunk/src/kash/var.c	(revision 2294)
@@ -255,5 +255,5 @@
 		vp->next = *vpp;
 		*vpp = vp;
-		vp->text = strdup(ip->text);
+		vp->text = sh_strdup(psh, ip->text);
 		vp->flags = ip->flags;
 		vp->func = ip->func;
@@ -265,5 +265,5 @@
 		psh->vps1.next = *vpp;
 		*vpp = &psh->vps1;
-		psh->vps1.text = strdup(sh_geteuid(psh) ? "PS1=$ " : "PS1=# ");
+		psh->vps1.text = sh_strdup(psh, sh_geteuid(psh) ? "PS1=$ " : "PS1=# ");
 		psh->vps1.flags = VSTRFIXED|VTEXTFIXED;
 	}
