News for hackers. Stuff that matters.
Re:Cmd - A saner way to running external programs from C# by MichaelGG on Saturday December 08, 2012 @04:01PM (#4892679)
This is a neat use of dynamic/reflection. But why is it "saner"? What's wrong with wrapping the normal process I/O stuff and just doing: cmd("git clone") ?

This is the same question I have when I see dynamic typing used to access data sources. Like reading a CSV file and doing 'row.Field1' instead of 'row["Field1"]'.

Is there really any benefit or point, other than being a cute hack?

Re:Cmd - A saner way to running external programs from C# by manojlds on Sunday December 09, 2012 @12:24AM (#4893913)
Yes, it started out as a hack. I wanted to see how close I can get to the Python implementation. I am not envisioning it to be used, but would be happy if someone found it useful :)
Re:Cmd - A saner way to running external programs from C# by duncans on Saturday December 08, 2012 @02:18PM (#4892416)
Nice idea. A few problems spring to mind:

* Doing the following will hang if the stdout buffer fills up:

    var output = process.StandardOutput.ReadToEnd();
    process.WaitForExit();
Take a look at Kudu (Azure's Git publishing platform) for the way they do it: https://github.com/projectkudu/kudu/blob/master/Kudu.Core/In...

* You need to expose a way to capture `StandardError`.

Re:Cmd - A saner way to running external programs from C# by timrobinson on Saturday December 08, 2012 @06:04PM (#4893032)
It won't hang as long as you're redirecting only standard output. If you want to read both StandardOutput and StandardError, you need to do it from separate threads: either with explicit BeginInvoke/EndInvoke calls as in Kudu, or more simply, by listening on the OutputDataReceived/ErrorDataReceived events then calling BeginOutputReadLine/BeginErrorReadLine.

(The reason for this is that the two streams are redirected to separate pipes, each of which has its own fixed-size buffer. If you forget to read from one pipe while you read from the other, its buffer fills up, and the writer - the program being executed - blocks. With standard error redirection turned off, the program writes directly to the console, which is safe.)

Re:Cmd - A saner way to running external programs from C# by manojlds on Sunday December 09, 2012 @12:25AM (#4893918)
Yes, I have so for been working on getting the Base API right. Will be adding background process, stderr redirect etc. Thanks for the input.
Re:Cmd - A saner way to running external programs from C# by daeken on Saturday December 08, 2012 @03:42PM (#4892626)
This looks quite awesome overall. I do wonder, though, why you can't do the actual invokation in Cmd.TryInvokeMember rather than Cmd.TryInvoke? That'll get rid of the () at the end of commands, from my quick read.
Re:Cmd - A saner way to running external programs from C# by manojlds on Sunday December 09, 2012 @12:36AM (#4893929)
I was thinking the same. I wanted to support cmd.git(git_dir : blah).branch(a: true) kind of scenarios however. Think I would just not go with it if it means removing the extra (). Thanks
Re:Cmd - A saner way to running external programs from C# by daeken on Sunday December 09, 2012 @12:45AM (#4893954)
Yeah, I think skipping the extra () is worth giving that up. Plus, you could do this in most cases: cmd.git.branch(a: true, git_dir: blah)
Re:Cmd - A saner way to running external programs from C# by manojlds on Monday December 10, 2012 @02:06PM (#4900902)
The ugly () are now gone. :)
Re:Cmd - A saner way to running external programs from C# by ComputerGuru on Saturday December 08, 2012 @02:10PM (#4892389)
This won't work for one very simple reason: Windows apps, unlike their *nix counterparts, do not have a unified command line switch format. This will only really be useful for standard getopt(long) implementations, which is a very small portion of the software available on Windows.
Re:Cmd - A saner way to running external programs from C# by manojlds on Sunday December 09, 2012 @12:28AM (#4893921)
Very valid point. I am working on the powershell equivalent for this, and I would be happy to support only powershell commands and standard getopt commands.