ZopoStyle

Hi,

I need to run an external application passing some parameters and then get all the results that this application print to the console...into a string...is there a way to do that

Can you give me an example

Thanks




Re: Visual C# General Running an external application to get the result

ArranNyc

To start a Process and pass parameters you can use :

Code Snippet
System.Diagnostics.Process.Start("myProg.exe", "myParameter");


To process the output, you will need to redirect StandardOutput. See the example in the following MSDN article :

http://msdn2.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx





Re: Visual C# General Running an external application to get the result

ZopoStyle

I'm using this (.net 1.1)

Process proc = new Process();

proc.StartInfo.RedirectStandardOutput = true;

proc.StartInfo.UseShellExecute = false;

proc.StartInfo.CreateNoWindow = true;

proc.StartInfo.FileName= "rrdtool.exe";

double hora_inicial=fco.diferenca_1970(dtDataInicial.Value).TotalSeconds;

double hora_final=fco.diferenca_1970(fco.converte_data(dtDataFinal.Value.ToShortDateString()+" 23:59:59")).TotalSeconds;

proc.StartInfo.Arguments="fetch "+txtCamimhoArquivo.Text+" MAX -s "+hora_inicial+" -e "+hora_final+" -r 86400";

proc.Start();

proc.WaitForExit();

string retorno="";

try

{

retorno=proc.StandardOutput.ReadToEnd();

}

catch(Exception err)

{

txtInformacoes.Text=err.Message;

}

And it's showing me an error: StandardOut could not be redirected

How can I solve this

I've run the command manually and it's working ok...






Re: Visual C# General Running an external application to get the result

ArranNyc

EDIT : I see that you have aleady done the following. ( I didn't see that line when I first read it.)

Not sure what's wrong then, I copied your code into my project and it worked.

You just need to add the following line before proc.Start();

Code Snippet

proc.StartInfo.RedirectStandardOutput = true;





Re: Visual C# General Running an external application to get the result

ZopoStyle

But now the problem is that the result is comming in blank...and it has more than 30 linis to print...




Re: Visual C# General Running an external application to get the result

ZopoStyle

I made it...I just change the line...

Code Snippet

proc.StartInfo.Arguments="fetch \""+txtCamimhoArquivo.Text+"\" MAX -s "+hora_inicial+" -e "+hora_final+" -r 86400";