Piping data when using Process class

T

Tenacious

I have been trying to run this program called mysqlbinlog.exe from my
main c# application using the Process class(See example below). The way
that mysqlbinlog functions is to read the first file in the command
line and pipe the results to the second file.

This works fine when actually run from a command window on XP, but when
I try to execute mysqlbinlog from the process class, mysqlbinlog runs
but does not pipe the result to the second file. Can anybody see what I
may be doing wrong here, or is there some trick that I do not know
about. Any assistance or suggestions would be very much appreciated.

private void Form1_Load(object sender, System.EventArgs e)
{
//Declare and instantiate a new process component.
System.Diagnostics.Process process1;
process1= new System.Diagnostics.Process();

process1.EnableRaisingEvents = false;

// Program file to run
string szProgFile = @"C:\Data\mysqlbinlog.exe";

// Cmd line arg to pipe results from rslog.001 to file1.txt
string strCmdLine = @"C:\Data\rslog.001 > C:\Data\file1.txt";

System.Diagnostics.Process.Start(szProgFile, strCmdLine);
process1.Close();
}
 
J

Jared Parsons [MSFT]

The problem is that the output redirect, when run from the command line, is
performed by the cmd shell. Try altering your program as follows
 
T

Tenacious

Thanks for the help. It is working correctly now. The only change that
I had to make was to the path statement in order to get the Windows
directory. Initially I kept getting file not found errors until I made
the change to:

string szProgFile = Environment.SystemDirectory + @"\cmd.exe";

Thanks Again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top