2010-09-24 28 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的答案。