Link to home
Start Free TrialLog in
Avatar of FPLNET
FPLNET

asked on

Passing a variable from a client-side Javascript Input box to .cmd file on server

Hello experts.  I have a simple test web page I want to develop.  On the page, I have an input box and a button, which when clicked is supposed to execute a .cmd file on the web server and use the inputted value in the input box as part of the parameters requested.  

This is the javascript on my webpage that I found when searching for how to do this:

<SCRIPT LANGUAGE="JavaScript">
function testResults (form) {
    var TestVar = form.inputbox.value;
    alert ("You typed: " + TestVar);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="myform" ACTION="" METHOD="GET">Enter something in the box: <BR>
<INPUT TYPE="text" NAME="inputbox" VALUE=""><P>
<INPUT TYPE="button" NAME="button" Value="Click" onClick="testResults(this.form)">
</FORM>

The function "testresults" is called when I click the button.  What I want to do instead of seeing an alert window (the sample provided) is to do something like call ASP code like this that I've used before:

<% dim oShell
Dim lRet
Set oShell = Server.CreateObject("Wscript.shell")
LRet=oShell.Run("C:\Test.cmd")
%>

The additional step I'd want to code is to run the "Test.cmd" and pass to it the value from the Input Box into the script that makes up the Test.cmd file.  This is the script when you edit the .cmd file:

"C:\Program Files\Testexecutable.exe" PassedValue=%TestVar%

So, my questions are a) how to properly write code to take the value placed in the Input Box to this script in my .cmd file and run the server side executable and b) is there a more efficient way to do this?  
Avatar of dxdinh
dxdinh
Flag of United States of America image

Can you try this

Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd /K C:\Program Files\Testexecutable.exe " _ TestVar

Or
Return = oShell.Run("C:\Program Files\Testexecutable.exe"  & TestVar, 1, true)

More on this
http://msdn.microsoft.com/en-us/library/d5fk67ky(VS.85).aspx
Avatar of FPLNET
FPLNET

ASKER

Thanks for the quick response--how would I code the 'onclick' part of the javascript and call the ASP code?  Is it created as a function or something? I suppose I should have made that a question as well...
ASKER CERTIFIED SOLUTION
Avatar of dxdinh
dxdinh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FPLNET

ASKER

I am fine with using Ajax if that's easier--at this point I've tried a number of things but no dice--I think the biggest problem I'm having is getting the right syntax down so the Javascript "onclick" event passes the value entered into the Input Value field to the command in the .cmd file I showed above.  I tried the code above but I was getting error messages (so I suspect something else along the way was wrong)...I'm fine tearing down what I have and starting from scratch if necessary.
Is it possible if you can post some of your snippet and error message that you have ... so I can have some ideas of what you are facing.