首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

Process种在webform中可以运行,但是在winform中却不可以运行

2012-08-26 
Process类在webform中可以运行,但是在winform中却不可以运行webform中的代码C# codeprotected void Button

Process类在webform中可以运行,但是在winform中却不可以运行
webform中的代码

C# code
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中的代码如下,但是不可以运行

C# code
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());            }        }


请教一下了,谢谢了

[解决办法]
请检查您每一步的完整路径,尤其是
string flash_file = Application.StartupPath + "\\FlashPaper2.2\\FlashPrinter.exe";
string file_storage = Application.StartupPath + "\\2.doc";
string file_bowze = Application.StartupPath + "\\2.swf";

你打印出看什么,真的存在这些路径吗?路径带空格吗?带空格要加引号
------解决方案--------------------


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

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

热点排行