Shell命令无法实时运行 [英] shell command not working on live

查看:86
本文介绍了Shell命令无法实时运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码,不能在iis上使用.但是在本地工作.
这段代码是将文件转换为wav文件,然后播放.

它将音频文件转换并存储在本地而不是IIS上


Following is my code and not working on iis. But working on local.
This code is to convert up file to wav file and play after.

It convert and store audio file on local but not on IIS


public void ExecuteCommandSync(object command)
   {
       try
       {
           string exepath;
           string AppPath = Request.PhysicalApplicationPath.Replace("http:\\", "");
           ////Get the application path
           //exepath = Server.MapPath("Up2Wav.exe");
           exepath = Server.MapPath("tmp/Up2Wav.exe");
           string strCmd = exepath + " " + command;
           StreamWriter _testData = new StreamWriter(Server.MapPath("data.txt"), true);
           _testData.WriteLine(strCmd);


           System.Diagnostics.ProcessStartInfo procStartInfo =
               new System.Diagnostics.ProcessStartInfo("cmd", "/c " + strCmd);
           // The following commands are needed to redirect the standard output.
           // This means that it will be redirected to the Process.StandardOutput StreamReader.
           procStartInfo.RedirectStandardOutput = true;
           procStartInfo.UseShellExecute = false;
           // Do not create the black window.
           procStartInfo.CreateNoWindow = true;
           // Now we create a process, assign its ProcessStartInfo and start it
           System.Diagnostics.Process proc = new System.Diagnostics.Process();
           proc.StartInfo = procStartInfo;
           proc.Start();
           // Get the output into a string
           string result = proc.StandardOutput.ReadToEnd();
           // Display the command output.
           Console.WriteLine(result);
           _testData.WriteLine(result);
           _testData.Close();
           _testData.Dispose();

       }
       catch (Exception objException)
       {
           // Log the exception
       }
   }

推荐答案

System.Diagnostics.Process.Start正常运行.

但是它始终在服务器上运行,而不是在客户端上运行-这就是后面代码中的代码在其中执行的地方.
因此,当您说Process.Start时,该应用程序将像以前一样在服务器上运行.在开发时,服务器和客户端是同一台机器,因此这正是您想要的.

您无法从服务器在客户端上运行任何应用程序:安全禁止它.
System.Diagnostics.Process.Start is working fine.

But it always runs on the Server, not the Client - that is where the code in the code behind is executed.

So when you say Process.Start, the application runs just as it used to - on the server. When you were developing, the server and client were the same machine, so it seemed to exactly what you wanted.

You cannot run any application on the client from the server: security forbids it.


就像这里的很多人一样,您似乎对ASP.net和客户端-服务器体系结构有严重的困惑. .您的C#代码在Web服务器上运行 –不在客户端上运行.它的工作是创建标记或其他资源(例如图像,脚本等),并将其发送到浏览器.在客户端(即带有浏览器的计算机)发生的所有事情就是渲染标记或资源,并运行JavaScript代码.

无法制作将在客户端计算机上运行的C#函数.您在后面的代码中所做的任何操作都只会在服务器上发生.生成过程在服务器上很少有意义,实际上,大多数专业的托管环境都不会授予ASP.net引擎这样做的权限.

考虑到Microsoft故意以模糊客户端和服务器之间边界的方式编写ASP.net,即在客户端上呈现的控件存在于服务器上",并在结果中的代码后面设置属性,因此这种混淆是可以理解的.在页面刷新或AJAX调用之后)客户端上的值更改,反之亦然.但它仍然是底层的标准Web服务器和浏览器客户端体系结构,了解这一点很重要.

在这种情况下,如果WAV转换器没有可嵌入的公共API,则实际上您仍然确实需要产生一个进程来运行它.但是,您需要在过程完成时响应客户端,并提供一个可供客户端用来检索WAV文件的URL.
Like a lot of people here, you seem to have serious confusion about ASP.net and the client-server architecture. Your C# code runs on the web server – not on the client. Its job is to create markup or other resources (e.g. images, scripts etc) which are sent to the browser. All that happens on the client side (i.e. the machine with the browser) is that the markup or resources are rendered, and JavaScript code is run.

You cannot make a C# function which will run on the client machine. Anything which you do in the code behind will only ever happen on the server. Spawning processes very rarely makes sense on the server, and in fact most professional hosting environments won''t give permission to the ASP.net engine to do so.

This confusion is understandable considering that Microsoft wrote ASP.net in a way which deliberately blurs the boundary between client and server, i.e. controls that are rendered on the client ''exist'' on the server, and setting properties in code behind results in (after a page refresh or AJAX call) values changing on the client, or vice versa. But it is still a standard web server and browser client architecture underneath, and it''s important to understand that.

In this case, if the WAV converter doesn''t have an embeddable public API, you still actually do need to spawn a process to run it. However, you need to respond to the client when the process finishes and give a URL that the client can use to retrieve the WAV file.


这篇关于Shell命令无法实时运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆