Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将嵌入式javascript代码写入c#.net_C#_.net_Javascript_Winforms - Fatal编程技术网

将嵌入式javascript代码写入c#.net

将嵌入式javascript代码写入c#.net,c#,.net,javascript,winforms,C#,.net,Javascript,Winforms,我有js文件如何在winform C#中添加, 我已经开发了前端,我想在点击按钮时运行js文件。 如果你提供这个片段,我会非常感谢你!!!!! 我想在windows窗体中运行javascript代码 谢谢。您可以使用cscript.exe在windows上执行JScript,并可以捕获标准输出 string output; using (Process cscript = new Process()) { // prepare the process cscript.StartI

我有js文件如何在winform C#中添加, 我已经开发了前端,我想在点击按钮时运行js文件。 如果你提供这个片段,我会非常感谢你!!!!! 我想在windows窗体中运行javascript代码
谢谢。

您可以使用cscript.exe在windows上执行JScript,并可以捕获标准输出

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();
}
字符串输出;
使用(Process cscript=new Process())
{
//准备过程
cscript.StartInfo.UseShellExecute=false;
cscript.StartInfo.CreateNoWindow=true;
cscript.StartInfo.RedirectStandardInput=false;
//RedirectStandardOutput应为True,以使用StandardOutput属性获取输出
cscript.StartInfo.RedirectStandardOutput=true;
cscript.StartInfo.FileName=“cscript.exe”;
cscript.StartInfo.Arguments=“”;
cscript.Start();
output=cscript.StandardOutput.ReadToEnd();
cscript.Close();
}
显然,您的JScript不能包含任何在windows上非法的语句


例如,在浏览器中运行JS时,它包含窗口对象。当您使用cscript.exe在shell中运行JS时,将不会有窗口对象,正如其他人在这里所述,您应该澄清您的场景。也就是说,对于如何从.Net应用程序运行javascript,我们有一个答案。

关于ASP.Net和Windows窗体同时涉及的问题,我们一点也不清楚。请提供更多详细信息。您试图用javascript做什么,导致您想从winform运行它?用winforms“构建网站”有什么关系?winforms到底是如何参与的!?你需要为你的问题提供更多的细节和背景。使用javascript在WinForms中进行验证??不,听起来越来越像是在构建一个WebForms应用程序,在这个应用程序中,通常使用javascript进行客户端验证。