2012-07-13 66 views
0

我正在嘗試編寫一個基於Web的應用程序,該應用程序將允許用戶在表單域中輸入信息(特別是整數),將作爲條目輸入的信息添加到.def文件中,在文件上運行「.exe」文件(用C++編寫),然後點擊「提交」按鈕後在屏幕上顯示輸出。我已經編寫了用JavaScript運行.exe文件的函數,但它們不起作用。以下是我迄今爲止:從Web應用程序運行.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 
%> 

有沒有人有一個更清潔的方式來創建吃了這個應用程序?這將非常感激。謝謝!

+3

你真的認爲一個網頁可以讓你在電腦上運行一個程序嗎?通常這就是所謂的漏洞... :) – 2012-07-13 19:26:09

+0

一個清潔工不會混合ASP和PHP?那麼你做這個作爲網絡,而不是Windows應用程序? – 2012-07-13 19:29:07

+0

這就是病毒如何傳播。爲什麼不做exe處理服務器端? – jrummell 2012-07-13 19:31:31

回答

0

不要這樣做。 JavaScript運行在客戶端計算機上,這意味着程序將在客戶端的計算機上運行,​​並且文件也需要在那裏。這打破了一個Web應用程序的目的。

此外,還有各種非常好的安全原因,不允許瀏覽器內的JavaScript運行本地可執行文件 - 如果支持,訪問一個網站可能會導致您的計算機運行format.exe。

首先,選擇一個服務器端的Web開發框架。不要試圖結合PHP & ASP.NET。其次,弄清楚在沒有文件系統和命令行實用程序的文件的情況下是否有辦法處理這個問題。你可以在你選擇的任何開發框架中做這個邏輯嗎?如果你不能,你需要弄清楚如何編寫一個文件,如何調出一個.exe文件以及如何返回結果。這些問題本身都不是特別棘手,我會按照這個順序一次一個地解決它們。