Created
January 20, 2010 02:04
-
-
Save BenHall/281520 to your computer and use it in GitHub Desktop.
Hack IronRuby to support executing and output of subprocess. This enables AutoSpec to work. Not 100% final solution, more PoC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [RubyMethod("open", RubyMethodAttributes.PrivateInstance)] | |
| [RubyMethod("open", RubyMethodAttributes.PublicSingleton)] | |
| public static RubyIO/*!*/ Open( | |
| RubyContext/*!*/ context, | |
| object self, | |
| [DefaultProtocol, NotNull]MutableString/*!*/ path, | |
| [DefaultProtocol, Optional]MutableString mode, | |
| [DefaultProtocol, DefaultParameterValue(RubyFileOps.ReadWriteMode)]int permission) { | |
| string fileName = path.ConvertToString(); | |
| RubyIO io; | |
| if (fileName.Length > 0 && fileName[0] == '|') | |
| { | |
| string cmd = fileName.Split(' ')[1].Trim(); | |
| string arguments = fileName.TrimStart(new[] { ' ', '|' }).Replace(cmd, "").Trim(); | |
| ProcessStartInfo info = new ProcessStartInfo(cmd + ".exe", arguments); | |
| info.RedirectStandardError = true; | |
| info.RedirectStandardOutput = true; | |
| info.RedirectStandardInput = true; | |
| info.CreateNoWindow = true; | |
| info.UseShellExecute = false; | |
| Process process = new Process(); | |
| process.StartInfo = info; | |
| process.OutputDataReceived += process_OutputDataReceived; | |
| process.ErrorDataReceived += process_ErrorDataReceived; | |
| process.Start(); | |
| io = new RubyIO(context, process.StandardOutput, process.StandardInput, IOModeEnum.Parse(mode)); | |
| } | |
| else | |
| { | |
| io = new RubyFile(context, fileName, IOModeEnum.Parse(mode)); | |
| SetPermission(context, fileName, permission); | |
| } | |
| return io; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment