2010-09-24 38 views
-1

我有js文件我如何添加,在winform C# 我已经开发了前端,我想按钮点击运行js文件。 我会感谢你,如果你提供的片段!!!!! 我想以windows窗体运行javascript代码 谢谢。编写嵌入式JavaScript代码到C#.net

+7

这里并不清楚发生了什么,就ASP.NET和Windows窗体同时参与而言。请给出更多的细节。 – 2010-09-24 10:44:14

+0

你想用javascript来做什么,导致你想从一个winform运行它? – 2010-09-24 12:16:00

+0

“构建网站”与winforms有什么关系? winforms如何参与!? – 2010-09-24 14:10:31

回答

0

您可以使用cscript.exe在windows上执行JScr​​ipt &可以从stdout捕获输出。

string output; 
using (Process cscript = new Process()) 
{ 
    // prepare the process 
    cscript.StartInfo.UseShellExecute = false; 
    cscript.StartInfo.CreateNoWindow = true; 
    cscript.StartInfo.RedirectStandardInput = false; 
    // RedirectStandardOutput should be True to get output using the StandardOutput property 
    cscript.StartInfo.RedirectStandardOutput = true; 
    cscript.StartInfo.FileName = "cscript.exe"; 
    cscript.StartInfo.Arguments = "<Path to your .js file>"; 

    cscript.Start(); 
    output = cscript.StandardOutput.ReadToEnd(); 
    cscript.Close(); 
} 

显然你的JScript中不能包含当您在它所包含的窗口对象浏览器中运行JS是在Windows

例如非法任何声明。当您使用cscript.exe在shell中运行JS时,将不会有窗口对象。

1

正如其他人在此处所述,您应该阐明您的方案。也就是说,this question有一个如何从.Net应用程序运行javascript的答案。