1

I have an answer set program (verified to work) which I would like to run within a C# console application. I want to redirect the output of that program to a text file which I can then read from later on. I tried:

string directory = @"C:\...\Clingo";
string clingoPath = "clingo.exe";
string inputPath = "Assignment2.lp";
string dataPath = "Data1.lp";
string outputPath = "result.txt";
string arguments = String.Format("1 \"{0}\" \"{1}\" >\"{2}\"", inputPath, dataPath, outputPath);

// Set the necessary properties for the process
ProcessStartInfo clingoProcessInfo = new ProcessStartInfo(clingoPath, arguments);
clingoProcessInfo.WorkingDirectory = directory;
clingoProcessInfo.UseShellExecute = false;

// Start the process
Process clingoProcess = Process.Start(clingoProcessInfo);

However, when run, I get the following error: "***ERROR: (clingo): '>result.txt': could not open input file!"

I would like to know how to fix that.

Frank Ibem
  • 828
  • 1
  • 11
  • 19
  • 1
    I've created a class to handle your problem. Check this question http://stackoverflow.com/questions/21848271/redirecting-standard-input-of-console-application/21848564#21848564 – Mihail Shishkov Apr 15 '15 at 18:59

1 Answers1

0
using System.IO;
if (!File.Exists(outputPath)) 
{
    FileStream fs = new FileStream(outputPath, FileMode.CreateNew);
}
//now do the rest of your stuff
mjw
  • 1,196
  • 1
  • 12
  • 19