[m-rev.] diff: implement io__call_system for .NET

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Feb 15 04:20:04 AEDT 2003


Estimated hours taken: 1
Branches: main

library/io.m:
	Implement io__call_system_code for .NET.

Workspace: /home/fjh/ws/hermes
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.289
diff -u -d -r1.289 io.m
--- library/io.m	13 Feb 2003 17:36:35 -0000	1.289
+++ library/io.m	14 Feb 2003 17:19:20 -0000
@@ -5736,23 +5736,44 @@
 	MR_update_io(IO0, IO);
 ").
 
-/* XXX Implementation needs to be finished.
-:- pragma foreign_proc("MC++",
-	io__call_system_code(Command::in, Status::out, _Msg::out,
-			IO0::di, IO::uo),
+:- pragma foreign_proc("C#",
+	io__call_system_code(Command::in, Status::out, Msg::out,
+			_IO0::di, _IO::uo),
 		[will_not_call_mercury, promise_pure, tabled_for_io],
 "
-		// XXX This could be better... need to handle embedded spaces.
-	MR_Integer index = Command->IndexOf("" "");
-	MR_String commandstr = Command->Substring(index);
-	MR_String argstr = Command->Remove(0, index);
-		// XXX	This seems to be missing...
-	mercury::runtime::Errors::SORRY(""foreign code for this function"");
-//	Diagnostics::Process::Start(commandstr, argstr);
-	Status = NULL;
-	MR_update_io(IO0, IO);
+	try {
+		// 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);
+
+		// debugging...
+		// System.Console.Out.WriteLine(
+		// 	""[command = "" + command + ""]"");
+		// System.Console.Out.WriteLine(
+		// 	""[arguments = "" + arguments + ""]"");
+
+		System.Diagnostics.Process process =
+			System.Diagnostics.Process.Start(command, arguments);
+		process.WaitForExit();
+		Status = process.ExitCode;
+		Msg = """";
+
+		// debugging...
+		// System.Console.Out.WriteLine(
+		// 	""[exitcode = "" + Status + ""]"");
+
+	}
+	catch (System.Exception e) {
+		Status = 127;
+		Msg = e.Message;
+
+		// debugging...
+		// System.Console.Out.WriteLine(
+		// 	""[message = "" + Msg + ""]"");
+	}
 ").
-*/
 
 io__command_line_arguments(_) -->
 	% This version is only used for back-ends for which there is no

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list