Mercurial > projects > ldc
comparison tango/example/system/process.d @ 132:1700239cab2e trunk
[svn r136] MAJOR UNSTABLE UPDATE!!!
Initial commit after moving to Tango instead of Phobos.
Lots of bugfixes...
This build is not suitable for most things.
author | lindquist |
---|---|
date | Fri, 11 Jan 2008 17:57:40 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:5825d48b27d1 | 132:1700239cab2e |
---|---|
1 /******************************************************************************* | |
2 copyright: Copyright (c) 2006 Juan Jose Comellas. All rights reserved | |
3 license: BSD style: $(LICENSE) | |
4 author: Juan Jose Comellas <juanjo@comellas.com.ar> | |
5 *******************************************************************************/ | |
6 | |
7 private import tango.io.Stdout; | |
8 private import tango.sys.Process; | |
9 private import tango.core.Exception; | |
10 | |
11 private import tango.text.stream.LineIterator; | |
12 | |
13 | |
14 /** | |
15 * Example program for the tango.sys.Process class. | |
16 */ | |
17 void main() | |
18 { | |
19 version (Windows) | |
20 char[] command = "ping -n 4 localhost"; | |
21 else version (Posix) | |
22 char[] command = "ping -c 4 localhost"; | |
23 else | |
24 assert(false, "Unsupported platform"); | |
25 | |
26 try | |
27 { | |
28 auto p = new Process(command, null); | |
29 | |
30 Stdout.formatln("Executing {0}", p.toString()); | |
31 p.execute(); | |
32 | |
33 Stdout.formatln("Output from process: {0} (pid {1})\n---", | |
34 p.programName, p.pid); | |
35 | |
36 foreach (line; new LineIterator!(char)(p.stdout)) | |
37 { | |
38 Stdout.formatln("{0}", line); | |
39 } | |
40 | |
41 Stdout.print("---\n"); | |
42 | |
43 auto result = p.wait(); | |
44 | |
45 Stdout.formatln("Process '{0}' ({1}) finished: {2}", | |
46 p.programName, p.pid, result.toString()); | |
47 } | |
48 catch (ProcessException e) | |
49 { | |
50 Stdout.formatln("Process execution failed: {0}", e.toString()); | |
51 } | |
52 catch (IOException e) | |
53 { | |
54 Stdout.formatln("Input/output exception caught: {0}", e.toString()); | |
55 } | |
56 catch (Exception e) | |
57 { | |
58 Stdout.formatln("Unexpected exception caught: {0}", e.toString()); | |
59 } | |
60 } |