]> www.infradead.org Git - users/dwmw2/vpnc-scripts.git/commitdiff
vpnc-script-win: dump stdout and stderr when a command fails
authorDaniel Lenski <dlenski@gmail.com>
Wed, 31 Mar 2021 21:21:52 +0000 (14:21 -0700)
committerDaniel Lenski <dlenski@gmail.com>
Thu, 1 Apr 2021 01:11:39 +0000 (01:11 +0000)
Technique borrowed from https://github.com/horar/vpnc-scripts/blob/master/vpnc-script-win.js

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
vpnc-script-win.js

index c671eebcfaa8ef6b7f907954915a939df554eb23..d69f5ed81f0c9c7b67ca975bf2f53bce5a4f39f8 100644 (file)
@@ -3,6 +3,21 @@
 // Sets up the Network interface and the routes
 // needed by vpnc.
 
+// --------------------------------------------------------------
+// Initial setup
+// --------------------------------------------------------------
+
+var accumulatedExitCode = 0;
+var ws = WScript.CreateObject("WScript.Shell");
+var env = ws.Environment("Process");
+var comspec = ws.ExpandEnvironmentStrings("%comspec%");
+
+// How to add the default internal route
+// 0 - As interface gateway when setting properties
+// 1 - As a 0.0.0.0/0 route with a lower metric than the default route
+// 2 - As 0.0.0.0/1 + 128.0.0.0/1 routes (override the default route cleanly)
+var REDIRECT_GATEWAY_METHOD = 0;
+
 // --------------------------------------------------------------
 // Utilities
 // --------------------------------------------------------------
@@ -14,7 +29,19 @@ function echo(msg)
 
 function run(cmd)
 {
-    return (ws.Exec(cmd).StdOut.ReadAll());
+    var oExec = ws.Exec(comspec + " /C \"" + cmd + "\" 2>&1");
+    oExec.StdIn.Close();
+
+    var s = oExec.StdOut.ReadAll();
+
+    var exitCode = oExec.ExitCode;
+    if (exitCode != 0) {
+        echo("\"" + cmd + "\" returned non-zero exit status: " + exitCode + ")");
+        echo("   stdout+stderr dump: " + s);
+    }
+    accumulatedExitCode += exitCode;
+
+    return s;
 }
 
 function getDefaultGateway()
@@ -29,17 +56,6 @@ function getDefaultGateway()
 // Script starts here
 // --------------------------------------------------------------
 
-var internal_ip4_netmask = "255.255.255.0"
-
-var ws = WScript.CreateObject("WScript.Shell");
-var env = ws.Environment("Process");
-
-// How to add the default internal route
-// 0 - As interface gateway when setting properties
-// 1 - As a 0.0.0.0/0 route with a lower metric than the default route
-// 2 - As 0.0.0.0/1 + 128.0.0.0/1 routes (override the default route cleanly)
-var REDIRECT_GATEWAY_METHOD = 0;
-
 switch (env("reason")) {
 case "pre-init":
     break;
@@ -196,3 +212,4 @@ case "disconnect":
 
     // FIXME: handle IPv6 split-excludes
 }
+WScript.Quit(accumulatedExitCode);