webform中的代码protected void Button1_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                string filename = FileUpload1.FileName;
                //string extension=Path.GetExtension(filename);  //获取后缀名
                string file_name = filename.Substring(0, filename.LastIndexOf("."));//获取不含扩展名的文件名
                string file_storage = Server.MapPath("~/File/storage/") + filename; //原文件存放的路径
                FileUpload1.SaveAs(file_storage);
                string file_bowze = Server.MapPath("~/File/bowze/") + file_name + ".swf"; //转换为SWF格式后存放的路径
                string flash_file = Server.MapPath("~/FlashPaper2.2/FlashPrinter.exe");
                Process pro = new Process();
                pro.StartInfo.FileName = "cmd"; //调用CMD线程
                pro.StartInfo.UseShellExecute = false;
                pro.StartInfo.RedirectStandardInput = true;  //注册输入指向
                pro.StartInfo.RedirectStandardOutput = true;  //注册输出指向
                pro.StartInfo.CreateNoWindow = true; //不建新窗口,这个属性可以根据需要自己设定
                pro.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;  //隐藏窗口
                pro.Start();
                string input = string.Format("{0} {1} -o {2}", flash_file, file_storage, file_bowze);  //类似于在DOS界面要输入的内容
                pro.StandardInput.WriteLine(input); //将内容写到DOS   ---个人是这么理解的
                pro.StandardInput.WriteLine("exit");
                pro.WaitForExit(600000);
                string output = pro.StandardOutput.ReadToEnd(); //这句一定要加,输出转换好的SWF格式文件到指定位置 ,我一开始没加怎么都得不到文件
                pro.Close(); //关掉线程
            }
        }这个在webform中是可以运行的
在winfrom中的代码如下,但是不可以运行private void button2_Click(object sender, EventArgs e)
        {
            string flash_file = Application.StartupPath + "\\FlashPaper2.2\\FlashPrinter.exe";
            string file_storage = Application.StartupPath + "\\2.doc";
            string file_bowze = Application.StartupPath + "\\2.swf";
            Process pro = new Process();
            pro.StartInfo.FileName = "cmd"; //调用CMD线程
            pro.StartInfo.UseShellExecute = false;
            pro.StartInfo.RedirectStandardInput = true;  //注册输入指向
            pro.StartInfo.RedirectStandardOutput = true;  //注册输出指向
            pro.StartInfo.CreateNoWindow = true; //不建新窗口,这个属性可以根据需要自己设定
            pro.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;  //隐藏窗口
            try
            {
                pro.Start();
                string input = string.Format("{0} {1} -o {2}", flash_file, file_storage, file_bowze);  //类似于在DOS界面要输入的内容
                pro.StandardInput.WriteLine(input); //将内容写到DOS   ---个人是这么理解的
                pro.StandardInput.WriteLine("exit");
                pro.WaitForExit(600000);
                string output = pro.StandardOutput.ReadToEnd(); //这句一定要加,输出转换好的SWF格式文件到指定位置 ,我一开始没加怎么都得不到文件
                pro.Close(); //关掉线程
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }请教一下了,谢谢了

解决方案 »

  1.   

    我的代码如下,在控制台应用程序中运行没有问题。            string filePath = filename;//需要转换的文件路径
                string swfPath = filePath.Substring(0, filePath.LastIndexOf('.')) + ".swf";
                if (!File.Exists(filePath) || File.Exists(swfPath)) { return; }            FileInfo finfo = new FileInfo(filePath);
                int time = ((int)(finfo.Length / (1024 * 1204))) * 20 + 20;
                Process pc = new System.Diagnostics.Process();
                pc.StartInfo.FileName = "flashprinter";//需要启动的程序路径
                pc.StartInfo.Arguments = string.Format("{0} -o {1}", filePath, swfPath);
                pc.StartInfo.CreateNoWindow = true;
                pc.StartInfo.UseShellExecute = false;
                pc.StartInfo.RedirectStandardInput = false;
                pc.StartInfo.RedirectStandardOutput = false;
                pc.StartInfo.RedirectStandardError = true;
                pc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                pc.Start();
                bool res = pc.WaitForExit(time * 1000);            pc.Close();
                pc.Dispose();
      

  2.   

    哪行代码报错?错误信息是什么?我早在WinForm里用过Process类,没任何问题,你不说明怎么个不可用,谁知道错在哪里?
      

  3.   

    在server2003中是可以的,但是在win7下是不行的,不知道为什么,求解谢谢了
      

  4.   

    请检查您每一步的完整路径,尤其是
              string flash_file = Application.StartupPath + "\\FlashPaper2.2\\FlashPrinter.exe";
                string file_storage = Application.StartupPath + "\\2.doc";
                string file_bowze = Application.StartupPath + "\\2.swf";你打印出看什么,真的存在这些路径吗?路径带空格吗?带空格要加引号
      

  5.   


    会不会是权限问题呢,在win7下,以管理员Administrator登录,试一下
      

  6.   

    不报错说明程序没错,而你CMD命令中执行另一个命令,那个命令的执行情况你并未捕获,你先将隐藏DOS窗口的代码去掉,并将DOS窗口“exit”退出的代码也去掉,手动关闭,这样才能进行调试DOS内部的执行情况。