J2EEUtils.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
  3. //
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining
  6. // a copy of this software and associated documentation files (the
  7. // "Software"), to deal in the Software without restriction, including
  8. // without limitation the rights to use, copy, modify, merge, publish,
  9. // distribute, sublicense, and/or sell copies of the Software, and to
  10. // permit persons to whom the Software is furnished to do so, subject to
  11. // the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be
  14. // included in all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. //
  24. using System;
  25. using System.Web.Util;
  26. using System.IO;
  27. using [email protected];
  28. using vmw.common;
  29. namespace System.Web.J2EE
  30. {
  31. internal static class J2EEUtils
  32. {
  33. public static int RunProc(string[] cmd)
  34. {
  35. java.lang.Runtime rt = java.lang.Runtime.getRuntime();
  36. java.lang.Process proc = rt.exec(cmd);
  37. StreamGobbler errorGobbler = new
  38. StreamGobbler(proc.getErrorStream(), "ERROR");
  39. StreamGobbler outputGobbler = new
  40. StreamGobbler(proc.getInputStream(), "OUTPUT");
  41. errorGobbler.start();
  42. outputGobbler.start();
  43. int exitVal = proc.waitFor();
  44. return exitVal;
  45. }
  46. }
  47. public class StreamGobbler : java.lang.Thread
  48. {
  49. java.io.InputStream _is;
  50. String _type;
  51. public StreamGobbler(java.io.InputStream ins, String type)
  52. {
  53. this._is = ins;
  54. this._type = type;
  55. }
  56. public override void run()
  57. {
  58. try
  59. {
  60. java.io.InputStreamReader isr = new java.io.InputStreamReader(_is);
  61. java.io.BufferedReader br = new java.io.BufferedReader(isr);
  62. String line=null;
  63. while ( (line = br.readLine()) != null)
  64. {
  65. #if DEBUG
  66. Console.WriteLine(_type + ">" + line);
  67. #endif
  68. }
  69. }
  70. catch (Exception ex)
  71. {
  72. #if DEBUG
  73. Console.WriteLine(ex);
  74. #endif
  75. }
  76. }
  77. }
  78. }
  79. #if !CODEDOM_SUPPORT
  80. //stubs for CodeDom symbols
  81. namespace System.CodeDom
  82. {
  83. public class CodeObject
  84. {
  85. protected CodeObject () { }
  86. public System.Collections.IDictionary UserData { get { throw new NotSupportedException (); } }
  87. }
  88. public class CodeExpression : CodeObject
  89. {
  90. protected CodeExpression () { }
  91. }
  92. }
  93. #endif