1

我有一个答案集程序(已验证可以工作),我想在 C# 控制台应用程序中运行它。我想将该程序的输出重定向到一个文本文件,然后我可以从中读取。我试过了:

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);

但是,运行时,我收到以下错误:“***ERROR: (clingo): '>result.txt': could not open input file!”

我想知道如何解决这个问题。

4

1 回答 1

0
using System.IO;
if (!File.Exists(outputPath)) 
{
    FileStream fs = new FileStream(outputPath, FileMode.CreateNew);
}
//now do the rest of your stuff
于 2015-04-15T18:55:27.653 回答