周末快下班了,写的这个程序执行不下去了。在线等高手一起讨论解决。

lookme_pk_you 2013-06-14 04:02:36
问题:就是执行到WaitForExit 这里执行不下了,错了也给应该有一个反馈吧。

程序的下载地址:正在上传,,,,先看代码,把,,,

StringBuilder sb = new StringBuilder();
public Form1()
{
InitializeComponent();





string apppath = System.AppDomain.CurrentDomain.BaseDirectory;
string extArguments = "";
string pfdFilePath = apppath + "a.pdf";
string swfFilePath = apppath + "b.swf";
Process process = new Process(); //创建进程对象

ProcessStartInfo startInfo = new ProcessStartInfo();

startInfo.FileName = apppath + "pdf2swf.exe";
startInfo.Arguments = pfdFilePath + " -s flashversion=9 -o " + swfFilePath + extArguments;

startInfo.UseShellExecute = false; //不使用系统外壳程序启动
startInfo.RedirectStandardInput = true; //不重定向输入
startInfo.RedirectStandardOutput = true; //重定向输出
startInfo.CreateNoWindow = true; //不创建窗口
startInfo.RedirectStandardError = true;

process.StartInfo = startInfo;

process.Start();


process.BeginOutputReadLine();
process.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler);
process.ErrorDataReceived += new DataReceivedEventHandler(SortOutputHandler);


process.WaitForExit();

}


void SortOutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
if (!String.IsNullOrEmpty(outLine.Data))
{
sb.Append(Environment.NewLine + "[" + numOutputLines.ToString() + "] - " + outLine.Data);
}
}
...全文
66 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
dd_zhouqian 2013-06-14
  • 打赏
  • 举报
回复
自己刚写了个例子,楼主参考下吧,waitforexit函数的意思是等待进程结束,调用进程执行完后,才会执行waitforexit下面的代码。

        private void button3_Click(object sender, EventArgs e)
        {
            string apppath = System.AppDomain.CurrentDomain.BaseDirectory;
            Process process = new Process();     //创建进程对象 
            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.FileName = "notepad.exe";
            startInfo.Arguments = "c:\\1.txt";

            startInfo.UseShellExecute = false;     //不使用系统外壳程序启动 
            startInfo.RedirectStandardInput = true;   //不重定向输入 
            startInfo.RedirectStandardOutput = true;   //重定向输出 
            startInfo.CreateNoWindow = true;     //不创建窗口 
            startInfo.RedirectStandardError = true;

            process.StartInfo = startInfo;
            process.Start();
            process.BeginOutputReadLine();
            process.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler);
            process.ErrorDataReceived += new DataReceivedEventHandler(SortOutputHandler);
            process.WaitForExit();
            MessageBox.Show("wait for exit"); 

        }
http://msdn.microsoft.com/zh-cn/library/vstudio/fb4aw7b8(v=vs.100).aspx

110,566

社区成员

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

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

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