[m-rev.] diff: C# io.call_system

Peter Wang novalazy at gmail.com
Thu Dec 9 14:39:36 AEDT 2010


Branches: main

Fix problems with C# implementation of io.call_system.

library/io.m:
        Handle command lines with no arguments.

        Set `UseShellExecute' property to false, so that it will never
        interpret the command as a document to open with whatever application
        is registered for that document type.  This also prevents creating a
        new window for console programs on Windows.

diff --git a/library/io.m b/library/io.m
index 5bd8305..e4b0707 100644
--- a/library/io.m
+++ b/library/io.m
@@ -9616,8 +9616,14 @@ io.handle_system_command_exit_code(Status0::in) = (Status::out) :-
         // XXX This could be better... need to handle embedded spaces
         // in the command name.
         int index = Command.IndexOf("" "");
-        string command = Command.Substring(0, index);
-        string arguments = Command.Remove(0, index + 1);
+        string command, arguments;
+        if (index > 0) {
+            command = Command.Substring(0, index);
+            arguments = Command.Remove(0, index + 1);
+        } else {
+            command = Command;
+            arguments = """";
+        }
 
         // debugging...
         // System.Console.Out.WriteLine(
@@ -9625,8 +9631,11 @@ io.handle_system_command_exit_code(Status0::in) = (Status::out) :-
         // System.Console.Out.WriteLine(
         //  ""[arguments = "" + arguments + ""]"");
 
-        System.Diagnostics.Process process =
-            System.Diagnostics.Process.Start(command, arguments);
+        System.Diagnostics.Process process = new System.Diagnostics.Process();
+        process.StartInfo.UseShellExecute = false;
+        process.StartInfo.FileName = command;
+        process.StartInfo.Arguments = arguments;
+        process.Start();
         process.WaitForExit();
         Status = process.ExitCode;
         Msg = """";

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list