[Mono-list] Capturing output from Linux Command Line programs

kevin mulholland Kevin.MULHOLLAND at uk.landisgyr.com
Tue Aug 16 07:09:09 EDT 2005


So the real question was, how can I capture the output of a linux
command line program so that I can use it as input within my mono
program.

A couple of ways suggest themselves

1. from within your app, run a shell process (spawn or whatever mono
uses) with command line prog (someprog > somefile) then read in somefile
and use that
2. some programming languages allow the output of a spawned/shelled
whatever process to be tied to a filehandle that can then be used to
pull in the data required


for the 2nd way, trawling back through this mailing list archive will
give an answer something like

public class GACReader
{
        private static void Main()
        {
                System.Diagnostics.Process GACRead;

                GACRead = new System.Diagnostics.Process();
                GACRead.StartInfo.FileName = "gacutil";
                GACRead.StartInfo.Arguments = " -l | grep Version=1";
                GACRead.StartInfo.UseShellExecute = true;
                GACRead.StartInfo.RedirectStandardOutput = false;
                GACRead.Start();

                contents = GACRead.StandardOutput.ReadToEnd();

                GACRead.WaitForExit();
                GACRead.Close();
        }
        
}

This won't compile as contents is undefined but you should get the idea
from it.

Another way to ask for help is to give a better idea of what you want to
achieve in plain english, an example in another programming language can
also help, and of course reading the mailing list archive, and not
dissing folk for answering the question you asked rather than the
question you thought you asked.

Hope this leads you to an answer you can use.

regards 
kevin


On Tue, 2005-08-16 at 10:54 +1000, mono-list.1.tracyanne at spamgourmet.com
wrote:
> > try using
> > 2>&1
> > instead of
> >  >
> > 
> > Joel.
> > 
> 
> I'm not not using the Command line, and nowhere have I used >.
> 
> I am trying to capture stdout from commandline programs so I can use that output in real time in a GUI application.
> 
> Can I have some sensible replies please.
> 
> Regards
> 
> Tracy Barlow
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
-- 
Kevin Mulholland
ICT Manager
Landis+Gyr Ltd
desk 00 44 161 919 8930
mobile 00 44 7947893810
--



More information about the Mono-list mailing list