我想更新一个1995年用Pascal或C编写的命令行程序,现在我使用的是C#。我想读取子程序的输出结果,这是否可能?
我尝试了一些方法,但没有成功。它们如下:
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "asdd.exe";
p.Start();
logs.AppendText("Timer Started\n");
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
// write somethingg and read what is the program doing on command line?
// What is the program printint? etc...
// I try this code but not enough for mo.
// logs.AppendText("d:" + p.StandardOutput.ReadToEnd()+"\n");
}
private void p_Exited(object sender, EventArgs e)
{
timer1.Enabled = false;
}
我可以翻译与Java、C++、C或C#相关的任何想法。
编辑:
例如:
我的asdd.exe程序源代码是
#include<stdio.h>
int main(){
printf("something\n");
printf("something, too\n");
}
这个程序使用C#编写,日志richTextBox会被追加:
something
something, too