I've no idea here...
[gtkD.git] / installer / ui / Exec.d
blobd5137570d07fc6ee5032a436085de1ec65d7aecf
1 /*
2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 module ui.Exec;
21 private import ui.Main;
23 private import gtk.MainWindow;
24 private import gtk.Widget;
25 private import gtk.ProgressBar;
26 private import gtk.Label;
27 private import gtk.VBox;
29 private import glib.Spawn;
31 private import gdk.Event;
33 private import compd.Compiler;
34 private import compd.Executor;
36 private import std.stdio;
38 /**
39 * Executes a command from the compiler
41 class Exec : Executor
44 int exitStatus;
46 char[][] output;
47 char[][] error;
49 void delegate(int) executionEnded;
51 public bool execute(char[] command, void delegate(int) executionEnded)
54 this.executionEnded = executionEnded;
56 //writefln("\ncwd : ", std.file.getcwd());
57 //writefln("exec command : %s", command);
59 version(Win32)
61 command = std.string.replace(command, "\\", "\\\\");
64 Spawn spawn = new Spawn(command);
66 int result = spawn.commandLineSync(
67 &childEnd,
68 &appendOutputLine,
69 &appendErrorLine
71 return result != 0;
74 public int getStatus()
76 return exitStatus;
79 public char[][] getOutput()
81 return output;
84 public char[][] getError()
86 return error;
89 bool childEnd(Spawn spawn)
91 exitStatus = spawn.exitStatus;
92 if ( executionEnded != null )
94 executionEnded(exitStatus);
97 return false;
101 * Add the line to the output text view and adds the line to the outputQueue
102 * Params:
103 * line = The line received from the child output stream
104 * Returns: false
106 bool appendOutputLine(char[] line)
108 //writefln("Output - %s", line);
109 output ~= line;
110 return false;
114 * Add the line to the output text view and adds the line to the outputQueue
115 * Params:
116 * line = The line received from the child error stream
117 * Returns: false
119 bool appendErrorLine(char[] line)
121 //writefln("Error - %s", line);
122 error ~= line;
123 return true;