超难!!C#调用tc编译器!

寂寞沙洲 2008-09-18 09:23:36
C#调用tc编译器,有如下要求:
1)编译文件test.c,并获取编译结果
2)若编译通过,连接,产生可执行文件test.exe,并运行test.exe,如果运行时要求输入数据,C#程序把数据传给test.exe,并获取运行结果。

感觉很困难,请大家帮忙,谢谢!!
...全文
198 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
msw_cn 2008-10-20
  • 打赏
  • 举报
回复
很想用用这个技术。
寂寞沙洲 2008-09-25
  • 打赏
  • 举报
回复
自己提前。
flyingfz 2008-09-23
  • 打赏
  • 举报
回复
mark
hwphu 2008-09-23
  • 打赏
  • 举报
回复
来 看看
JeffChung 2008-09-22
  • 打赏
  • 举报
回复
来看看超难的题目
Inpool 2008-09-21
  • 打赏
  • 举报
回复
^_*
Odesky 2008-09-21
  • 打赏
  • 举报
回复
不懂 ~学习中。。。。
寂寞沙洲 2008-09-21
  • 打赏
  • 举报
回复
我用了下面的代码,运行时可以出现tc界面,但不知如何控制tc编译test.c:

ProcessStartInfo psi = new ProcessStartInfo(@"E:\tc\tc\tc.exe");
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.UseShellExecute = false;
Process p = Process.Start(psi);

p.StandardInput.WriteLine(@"Load test.c");
p.StandardInput.WriteLine(@"exit");

string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
请高手能否贴出相应的代码,谢谢!急用!
寂寞沙洲 2008-09-21
  • 打赏
  • 举报
回复
谢谢大家的回答,等我试过后再给分!也请高手继续指点!
寂寞沙洲 2008-09-21
  • 打赏
  • 举报
回复
如何用C#控制tc进行编译、链接、运行程序。请大家指点!!
KnowDotNet 2008-09-18
  • 打赏
  • 举报
回复
DOS时代就有管道技术了。 那时候都可以实现你的要求啦。 哈哈
wolf_life 2008-09-18
  • 打赏
  • 举报
回复
期待楼主解决。。学习。。

希望大家没喝过牛奶。
yagebu1983 2008-09-18
  • 打赏
  • 举报
回复
管道技术!!
brallow 2008-09-18
  • 打赏
  • 举报
回复

Process p = new Process();
p.StartInfo.FileName = @"C:\windows\system32\command.com";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;

p.Start();

p.StandardInput.WriteLine("dir");
string s = p.StandardOutput.ReadToEnd();

Console.WriteLine(s);

Console.ReadKey();



发我刚才的一段测试代码:
程序的输出为:
Volume in drive E is Data
Volume Serial Number is 9672-0439

Directory of E:\Project\CTest2\CTest2\bin\Debug

2008-09-17 15:44 <DIR> .
2008-09-17 15:44 <DIR> ..
2008-09-18 09:48 5,120 CTest2.exe
2008-09-18 09:48 13,824 CTest2.pdb
2008-09-18 09:48 14,328 CTest2.vshost.exe
3 File(s) 33,272 bytes
2 Dir(s) 16,306,057,216 bytes free

  • 打赏
  • 举报
回复
都是用Process调用,先调用编译器。编译成功了。在用新的Process调用你的exe文件。用C#传数据看看下面这个例子吧。
class StandardInputTest
{
static void Main()
{
Console.WriteLine("Ready to sort one or more text lines...");

// Start the Sort.exe process with redirected input.
// Use the sort command to sort the input text.
Process myProcess = new Process();

myProcess.StartInfo.FileName = "Sort.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;

myProcess.Start();

StreamWriter myStreamWriter = myProcess.StandardInput;

// Prompt the user for input text lines to sort.
// Write each line to the StandardInput stream of
// the sort command.
String inputText;
int numLines = 0;
do
{
Console.WriteLine("Enter a line of text (or press the Enter key to stop):");

inputText = Console.ReadLine();
if (inputText.Length > 0)
{
numLines ++;
myStreamWriter.WriteLine(inputText);
}
} while (inputText.Length != 0);


// Write a report header to the console.
if (numLines > 0)
{
Console.WriteLine(" {0} sorted text line(s) ", numLines);
Console.WriteLine("------------------------");
}
else
{
Console.WriteLine(" No input was sorted");
}

// End the input stream to the sort command.
// When the stream closes, the sort command
// writes the sorted text lines to the
// console.
myStreamWriter.Close();


// Wait for the sort process to write the sorted text lines.
myProcess.WaitForExit();
myProcess.Close();

}
}

// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "Write500Lines.exe";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
nattystyle 2008-09-18
  • 打赏
  • 举报
回复
回帖是一种美德!传说每天回帖即可获得 10 分可用分!
Red_angelX 2008-09-18
  • 打赏
  • 举报
回复
这不是标准的管道技术么... 又何难得.
优途科技 2008-09-18
  • 打赏
  • 举报
回复
前半部分一点难度也没有,直接调用shell的指令运行编译器编译即可。
后半部分中输入的数据和输出略有些麻烦,不过把那个程序的STDIN和STDOUT接管一下就可以了
、、、、、、、、、、、
顶顶。
brallow 2008-09-18
  • 打赏
  • 举报
回复
前半部分一点难度也没有,直接调用shell的指令运行编译器编译即可。
后半部分中输入的数据和输出略有些麻烦,不过把那个程序的STDIN和STDOUT接管一下就可以了。
ZengHD 2008-09-18
  • 打赏
  • 举报
回复
tc编译器应该支持命令行吧
调用吧

111,127

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧