Just sharing some of my inconsequential lunch conversations with you... RSS  

Thursday, April 03, 2008

Redirecting stdin and stdout

We've been working on probabilistic meta-algorithms for the global optimization problem. I'm afraid I can't talk much about the project for the time being except for details. Here's a one of those details.

As strange as it may seem today I had the need to redirect stdin and stdout from within .NET. On one of the alternative solution branches we've decided to use lp_solve to optimize some variables so we could benchmark an alternative way for solving our algorithm.

The problem has so many variables and restrictions that we couldn't use lp_solve as a lib, we had to create the input file, execute lp_solve.exe and recover the outputted data.

Here's where stdin and stdout redirection came in. Here's how we did it:

	Process process = new Process();

process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = String.Format(
"/c {0} < \"{1}\" > \"{2}\"",
System.Configuration.ConfigurationSettings.AppSettings["LPSOLVE_PATH"] + @"\lp_solve.exe",
And there you go. Not much, but it works. And it sure brings back memories... :)

No comments:

Development Catharsis :: Copyright 2006 Mário Romano