0

我正在尝试编写一个基于 Web 的应用程序,该应用程序将允许用户将信息(特别是整数)输入到表单字段中,将输入的信息添加为 .def 文件中的条目,运行“.exe”文件(用 C++ 编写) ),然后在单击“提交”按钮后在屏幕上显示输出。我已经编写了在 JavaScript 中运行 .exe 文件的函数,但它们不起作用。这是我到目前为止所拥有的:

输入屏幕具有以下代码(HTML 文件):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head></head>><body><h1><i>The University of Vermont<br>Department of Medical     Biostatistics<br>Study Randomization Page</i></h1>
<?php
    $study = "study";
    $site = "site";
    $gender = "gender";
    $age = "age";
    $result = "result";
?>

Please Input Your Study Information Below:<br><br>
<form id="form1" action="file:///C:/Documents and Settings/cody/Desktop/DMB_RD_2.php"     method="post">
Study Number:<br>   <input name="study" type="int"><br>
Site Number:<br>    <input name="site" type="int"><br>
Subject Gender:<br> <input name="gender" type="int"><br>
Subject Age:<br>    <input name="age" type="int"><br>
Lab Result:<br>     <input name="result" type="int"><br>
<input value="Submit" class="button" type="submit">
</form>
</body></html>
Here is the page it is connected to (PHP file);
<script type="text/javascript" src="DMB++2JS.js"></script>
<script type="text" src="DMB Round 2.html"></script>
</head>
Here is the information that you input:<br /><br />
Study Number: <?php echo $_POST["study"]; ?><br />
Site Number: <?php echo $_POST["site"]; ?><br />
Subject Gender: <?php echo $_POST["gender"]; ?><br />
Subject Age: <?php echo $_POST["age"]; ?><br />
Lab Result: <?php echo $_POST["result"]; ?><br />
<br />
The following functions will randomize your data. Please indicated which method you would like to use by clicking on the button of the randomization method that you would like to use:<br /><br />
<input type="button" href="blockfn()" onclick="javascript:blockfn(); return     true;">Block Function</button><br />
<input type="button" href="d2rfn()" onclick="javascript:d2rfn(); return true;">Random Distance Function</button><br />
<input type="button" href="d2dfn()" onclick="javascript:d2dfn(); return true;">Determinate Distance Function</button><br />
<input type="button" href="minimizefn()" onclick="javascript:minimizefn(); return true;">Minimization Function</button><br />
<input type="button" href="pocockfn()" onclick="javascript:pocockfn(); return true;">Pocock Function</button><br />
</body>
</html>

这是其中编写了函数的 JavaScript 文件:

function d2rfn(){
    var oShell = new ActiveXObject("Shell.Application");
    var commandtoRun = "C:\Documents and Settings\cody\Desktop\C++ Programs\D2R001.def"; 
    oShell.ShellExecute(commandtoRun,"","","open","1");
}
function d2dfn(){
    var oShell = new ActiveXObject("Shell.Application");
    var commandtoRun = "C:\Documents and Settings\cody\Desktop\C++ Programs\D2D001.def"; 
    oShell.ShellExecute(commandtoRun,"","","open","1");
}
function minimizefn(){
    var oShell = new ActiveXObject("Shell.Application");
    var commandtoRun = "C:\Documents and Settings\cody\Desktop\C++ Programs\MINIMIZE001.def"; 
    oShell.ShellExecute(commandtoRun,"","","open","1");
}
function pocockfn(){
    var oShell = new ActiveXObject("Shell.Application");
    var commandtoRun = "C:\\Documents and Settings\\cody\\Desktop\\C++ Programs\\POCOCK2001.def"; 
    oShell.ShellExecute(commandtoRun,"","","open","1");
}
//Another possible way of calling the .exe file from the web interface.
var objShell = new ActiveXObject("WScript.Shell");
</script>

最后,我用 ASP 编写文件(这不起作用):

<%
    dim Study
    Study=Request.QueryString("Study")
    If Study<>"" Then
      Response.Write(Study)
    End If
    dim Site
    Site=Request.QueryString("Site")
    If Site<>"" Then
      Response.Write(Site)
    End If    
    dim Gender
    Gender=Request.QueryString("Gender")
    If Gender<>"" Then
      Response.Write(Gender)
    End If
    dim Age
    Age=Request.QueryString("Age")
    If Age<>"" Then
      Response.Write(Age)
    End If
    dim Result
    Result=Response.QueryString("Result")
    If Result<>"" Then
      Response.Write(Result)
    End If
%>

有没有人有更简洁的方法来创建这个应用程序?将不胜感激。谢谢!

4

1 回答 1

0

不要这样做。javascript 在客户端计算机上运行,​​这意味着程序将在客户端计算机上运行,​​并且文件也需要在那里。这违背了拥有 Web 应用程序的目的。

此外,还有各种非常好的安全原因不允许浏览器内的 javascript 运行本地可执行文件 - 如果支持,访问网站可能会导致您的计算机运行,例如 format.exe。

首先,选择一个单一的服务器端 Web 开发框架。不要尝试将 PHP 和 ASP.NET 结合起来。其次,弄清楚是否有一种方法可以在没有文件系统上的文件和命令行实用程序的情况下处理这个问题。您可以在您选择的任何开发框架中执行此逻辑吗?如果不能,则需要弄清楚如何编写文件、如何调用 .exe 以及如何返回结果。这些问题都不是特别棘手的,我会按顺序一次解决一个。

于 2012-07-13T20:50:31.800 回答