Solved

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

Posted on 2010-11-08
5
546 Views
Last Modified: 2012-05-10
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?  
0
Comment
Question by:FPLNET
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:dxdinh
ID: 34086008
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
0
 

Author Comment

by:FPLNET
ID: 34086102
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...
0
 
LVL 7

Accepted Solution

by:
dxdinh earned 500 total points
ID: 34086490
with classic ASP you would have to create page and using javascript to redirect the page with the parameter in the querystring

function Something_OnClick ()
{
 var p1 = "TestVar";
  self.document.location = "MyPage.asp?param1=" + p1;
}

 if you using JQuery you can leverage a lot of using AJAX call and make your page load faster.
 
0
 

Author Comment

by:FPLNET
ID: 34087623
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.
0
 
LVL 7

Expert Comment

by:dxdinh
ID: 34088393
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.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question