      my $dbh            = C4::Context->dbh;
 diff --git a/Koha/Auth.pm b/Koha/Auth.pm
 new file mode 100644
-index 0000000..673b0cf
+index 0000000..0eacafb
+@@ -0,0 +1,259 @@
 --- /dev/null
 +++ b/Koha/Auth.pm
-@@ -0,0 +1,249 @@
 +use strict;
 +use warnings;
 +

+        }
+        waitpid($pid, 0);
+    }
+    #warn "decoding($data)";
+    my ($out, $headers, $err) = @{ $JSON->decode($data) };
+

+
+    if (0==$pid) { # CHILD
+        $pipe->writer;
+
+        # scripts might exit(), and there is no way to prevent that without changing the script behavior
+        # so instead, let it exit, but first send the data back to the parent
+        # (note: this might now work with END {} blocks)
+        local $out = '';
+        local $headers = {};
+        local $err;
+        no warnings;
+        local *CORE::GLOBAL::exit = sub {
+            eval {
+                $pipe->print($JSON->encode([$out, $headers, $err]));
+                $pipe->close;
+                1;
+            } or warn $@;
+            CORE::exit($_[0]//0);
+        };
+        use warnings;
+
+        eval {
+            $self->cgi_subprocess($env, $file);
+            1;
+        } or do {
+            $err = "$@";
+            warn $@;
+        };
+        exit;
+    }
+
