1 using System;
2 using System.Threading;
3
4 int main(int argc, const char** argv)
5 {
6 try
7 {
8 string command;
9 command.Append("testprog");
10 for (int i = 1; i < argc; ++i;)
11 {
12 command.Append(' ').Append(argv[i]);
13 }
14 string errors;
15 Process process(command,
16 cast<Process.Redirections>(Process.Redirections.processStdIn | Process.Redirections.processStdOut | Process.Redirections.processStdErr));
17 while (!process.Eof(Process.StdHandle.stdOut))
18 {
19 string line = process.ReadLine(Process.StdHandle.stdOut);
20 if (!line.IsEmpty())
21 {
22 Console.WriteLine(line);
23 }
24 }
25 errors = process.ReadToEnd(Process.StdHandle.stdErr);
26 process.WaitForExit();
27 int exitCode = process.ExitCode();
28 if (exitCode != 0)
29 {
30 throw Exception("testprog returned exit code " + ToString(exitCode) + ": " + errors);
31 }
32 else
33 {
34 Console.WriteLine("testprog returned exit code 0");
35 }
36 }
37 catch (const Exception& ex)
38 {
39 Console.Error() << ex.Message() << endl();
40 return 1;
41 }
42 return 0;
43 }