JCDS

Hello all,

I have a vbs script which executes the following line passing a bunch of arguments:

set objExec = objShell.Exec(path & " " & version & " " & webservice & " " & strLine)

The command line looks like this:

C:>\Tools\UpdateDevice.exe "1.1.3945.1" "http://localhost/bss/PrincipalManagement.asmx" "11111"

I manage to execute that from C# in the following way:


const String strToolPath = "c:\\Tools\\UpdateDevice.exe";
const String strWebService = "http://localhost/bss/PrincipalManagement.asmx";

string strArguments = " " + strVersion + " " + strWebService + " " + strGuid;


try
{
System.Diagnostics.Process.Start(strToolPath, strArguments);
}
catch ( Exception ex )
{
System.Diagnostics.EventLog.WriteEntry("STBUpdate", ex.Message, EventLogEntryType.Error, 1111);
}
finally
{

}

HOWEVER, the executable itself is managing the exception and it throws the error in the DOS window then it returns to the C# program and I only see the error in the screen.

How do I capture that error so that I can show the error inside my C# code

Thank you

JCDS




Re: Visual C# General How to run a .EXE file from C# and obtain(pipe) the results from DOS windows back into the C#

Michael Letterle

You'll have to redirect StandardOutput (and/or StandardError) see my post on this other thread for an example.




Re: Visual C# General How to run a .EXE file from C# and obtain(pipe) the results from DOS windows back into the C#

JCDS

Michael,

That pointed me to the right direction. Thank you so much.
The only thing I am curious about is the lines below:


p.Start();
StreamReader reader = p.StandardOutput;
StreamWriter writer = p.StandardInput;
writer.AutoFlush = true;
writer.Write("ls\n"); <==== what do these do
writer.Write("exit\n"); <==== what do these do
s = reader.ReadToEnd();
Console.WriteLine(s);
Console.ReadLine();

Thank you

JCDS






Re: Visual C# General How to run a .EXE file from C# and obtain(pipe) the results from DOS windows back into the C#

Michael Letterle

In the content of that program I'm sending commands to the plink executable through the redirected StandardInput, in this case I was running the "ls" command in the linux shell I had connected to. In the situation you're referring to you don't seem to have to worry about the StandardInput section.




Re: Visual C# General How to run a .EXE file from C# and obtain(pipe) the results from DOS windows back into the C#

JCDS

That is what I thought :-))))

Thank you!