X-Git-Url: http://nitlanguage.org diff --git a/lib/core/exec.nit b/lib/core/exec.nit index 4190d3f..97ee3fa 100644 --- a/lib/core/exec.nit +++ b/lib/core/exec.nit @@ -23,8 +23,10 @@ in "C" `{ #include #include #include - #include #include +#ifndef _WIN32 + #include +#endif `} in "C Header" `{ @@ -59,14 +61,16 @@ class Process end # The status once finished + # + # Require: `is_finished` fun status: Int do assert is_finished return data.status end - # The executable run - # Is a filepath, or a executable found in PATH + # The target executable + # Either a file path or the name of an executable available in PATH. var command: Text # The arguments of the command @@ -88,13 +92,13 @@ class Process execute end - # flags used internally to know whith pipe to open + # Flags used internally to know which pipe to open private fun pipeflags: Int do return 0 # Internal code to handle execution protected fun execute do - # The pass the arguments as a big C string where elements are separated with '\0' + # Pass the arguments as a big C string where elements are separated with '\0' var args = new FlatBuffer var l = 1 # Number of elements in args args.append(command) @@ -102,7 +106,6 @@ class Process if arguments != null then for a in arguments do args.add('\0') - #a.output_class_name args.append(a) end l += arguments.length @@ -111,7 +114,11 @@ class Process end private var data: NativeProcess - private fun basic_exec_execute(prog, args: NativeString, argc: Int, pipeflag: Int): NativeProcess `{ + private fun basic_exec_execute(prog, args: CString, argc: Int, pipeflag: Int): NativeProcess `{ +#ifdef _WIN32 + // FIXME use a higher level abstraction to support WIN32 + return -1; +#else se_exec_data_t* result = NULL; int id; int in_fd[2]; @@ -206,6 +213,7 @@ class Process } return result; +#endif `} end @@ -292,7 +300,7 @@ class ProcessDuplex # ~~~ fun write_and_read(input: Text): String do - var read = new Buffer #new Array[String] + var read = new Buffer # Main loop, read and write line by line var prev = 0 @@ -330,16 +338,18 @@ redef class Sys fun pid: Int `{ return getpid(); `} end -redef class NativeString +redef class CString # Execute self as a shell command. # # See the posix function system(3). fun system: Int `{ int status = system(self); +#ifndef _WIN32 if (WIFSIGNALED(status) && WTERMSIG(status) == SIGINT) { // system exited on SIGINT: in my opinion the user wants the main to be discontinued kill(getpid(), SIGINT); } +#endif return status; `} end @@ -353,6 +363,10 @@ private extern class NativeProcess `{ se_exec_data_t* `} fun err_fd: Int `{ return self->err_fd; `} fun is_finished: Bool `{ +#ifdef _WIN32 + // FIXME use a higher level abstraction to support WIN32 + return 0; +#else int result = (int)0; int status; if (self->running) { @@ -368,14 +382,18 @@ private extern class NativeProcess `{ se_exec_data_t* `} result = (int)1; } return result; +#endif `} fun wait `{ +#ifndef _WIN32 + // FIXME use a higher level abstraction to support WIN32 int status; if (self->running) { waitpid(self->id, &status, 0); self->status = WEXITSTATUS(status); self->running = 0; } +#endif `} end