如何发送用户输入到cmd应用程序并获取输出结果? [英] How to send user input to cmd application and get back the output result?

查看:675
本文介绍了如何发送用户输入到cmd应用程序并获取输出结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了.html文件,它接受用户的输入并返回一些输出。



输入是查询序列和数据库名称。



我想将查询序列放在txt文件并通过类型执行本地程序cmd应用程序:

  blastn -query querySequence.txt -db databaseName -out outputFile。 txt 

然后,将输出文件提供给用户。



我使用windows 7.我认为perl是一个解决方案,但我不知道任何关于perl和它是如何工作的。

解决方案

CommandLine.hta的屏幕截图





因此,只需将此代码复制并粘贴到记事本或notepad ++上,并将其另存为 CommandLine.hta 。扩展程序必须是 .hta ,而不是 .html / em>

 < html& 
< title>由Hackoo执行HTA的命令行< / title>
< head>
< HTA:APPLICATION
APPLICATIONNAME =由Hackoo执行HTA的命令行
SCROLL =no
SINGLEINSTANCE =yes
WINDOWSTATE =最大化
ICON =Winver.exe
/>
< / head>
< META HTTP-EQUIV =MSThemeCompatibleCONTENT =YES>
< script language =VBScript>
选项显式
Dim标题:Title =Hackoo使用HTA执行命令行
'******************** **************************************************** ************************
子窗口_OnLoad
调用Run_Cmd(帮助)
结束子
'************************************************ **********************************************
Sub Run_Cmd(strCommand)
在错误恢复下
如果input.value =然后
MsgBox注意!文本框是空的! vbcr& _
您忘了在文本框中键入命令!,vbExclamation,标题
input.value =help
退出子
如果$ b结束$ b Output.value =
btnClick.disabled = True
document.body.style.cursor =wait
btnClick.style.cursor =wait
Const ForReading = 1
Const TristateTrue = -1
Const TemporaryFolder = 2
Const WshHide = 0
Dim wsh,fs,ts
Dim strTempFile,strFile,strData
设置wsh = CreateObject(Wscript.Shell)
设置fs = CreateObject(Scripting.FileSystemObject)
strTempFile = fs.BuildPath(fs.GetSpecialFolder(TemporaryFolder).Path,fs.GetTempName )
strFile = fs.BuildPath(fs.GetSpecialFolder(TemporaryFolder).Path,result.txt)
wsh.Runcmd.exe / c& strCommand& >& DblQuote(strTempFile)& 2& 1,WshHide,True
wsh.Runcmd.exe / u / c Type& DblQuote(strTempFile)& >& DblQuote(strFile)& ,WshHide,True
Set ts = fs.OpenTextFile(strFile,ForReading,True,TristateTrue)
strData = ts.ReadAll
Output.Value =Microsoft Windows [version 7.1 7631] & vbcrlf& _
版权所有(c)2009 Microsoft Corporation。保留所有权利。 &安培; vbcrlf& vbcrlf& _
C:\>& strCommand& vbcrlf& strData
ts.Close
fs.DeleteFile strTempFile
fs.DeleteFile strFile
document.body.style.cursor =default
btnClick.style.cursor = default
btnClick.disabled = False
End Sub
'**************************** **************************************************** ****************
函数DblQuote(Str)
DblQuote = Chr(34)& Str& Chr(34)
结束函数
'*********************************** **************************************************** *********
Sub OnClickButtonCopy()
document.parentwindow.clipboardData.SetDatatext,Output.Value
MsgBox输出结果被复制到剪贴板! ,vbInformation,Title
End Sub
'********************************** **************************************************** **********
< / script>
< / head>
< body bgcolor =123456text = Darkorange>
< hr>
< center>< FONT SIZE =3>< B>< I>命令< / I>< / FONT>
< select style =background-color:lightbluename =DropDown>
< option value =Tasklist>任务列表< / option>
< option value =CD%Programfiles%\Mozilla Firefox\ |启动Firefox.exe> CD%Programfiles%\Mozilla Firefox\ |启动Firefox.exe< / option>
< option value =Tracert www.google.fr> Tracert www.google.fr< / option>
< option value =Start iexplore>启动iexplore< / option>
< option value =开始记事本>开始记事本< / option>
< option value =开始Winword>开始Winword< / option>
< option value =Explorer.exe / n,/ e,/ root,C:\Program Files> Explorer.exe / n,/ e,/ root,C:\Program Files< / option>
< option value =Ipconfig> IpConfig< / option>
< option value =Dir> Dir< / option>
< option value =Ping www.yahoo.fr> Ping www.yahoo.fr< / option>
< option value =Ping www.google.fr> Ping www.google.fr< / option>
< option value =Taskkill / im iexplore.exe / f> Taskkill / im iexplore.exe / f< / option>
< / select>
< input type =buttononClick =Run_Cmd(DropDown.value)value =运行此命令>
< center>< hr>< B>< I>在此输入您的输入命令< / I>< / B&
< input type =textName =inputsize =10style =width:100%value =Ping www.google.comstyle =background-color:lightblue> ;
< input type =submitname =btnClickvalue =运行输入命令行onclick =Run_Cmd(input.value)>
< br>< hr>< B>< I>输出结果(只读)< / I>< / B>< hr>
< textarea readonly id =Outputstyle =width:100%rows =28style =background-color:black; color:Darkorange> Microsoft Windows [version 7.1 7631]
版权所有(c)2009 Microsoft Corporation。版权所有。
C:\>< / textarea>< input type =buttonname =ButtonCopyvalue =将输出结果复制到剪贴板onclick =OnClickButtonCopy>
< hr>< / center>
< / body>
< / html>


I design ".html" file that takes inputs from the user and returns some outputs.

The inputs are Query sequence and Name of database.

I want to put the query sequence in a txt file and execute the local program "cmd application" by type:

blastn -query querySequence.txt -db databaseName -out outputFile.txt

Then, present the output file to the user.

I am using windows 7. I think perl is a solution but I did not know anything about perl and how it is working!

解决方案

Screenshot of CommandLine.hta

So, just copy and paste this code on your notepad or notepad++ and save it as CommandLine.hta and execute it by double clic.

NB : The extension must be .hta and not .html

<html>
<title>Execution of command line with HTA by Hackoo</title>
<head>
<HTA:APPLICATION 
     APPLICATIONNAME="Execution of command line with HTA by Hackoo"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="maximize"
     ICON="Winver.exe"
/>
</head>
<META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES">
<script language="VBScript">
Option Explicit
Dim Title : Title = "Execution of command line with HTA by Hackoo"
'**********************************************************************************************
Sub Window_OnLoad
    Call Run_Cmd("help")
End Sub
'********************************************************************************************** 
Sub Run_Cmd(strCommand)
On Error Resume Next
    If input.value = "" Then
        MsgBox "ATTENTION ! The text box is empty !"& vbcr &_
        "You forgot to type a command on the text box !",vbExclamation,Title
        input.value = "help"
        Exit Sub
    End if
    Output.value = ""
    btnClick.disabled = True
    document.body.style.cursor = "wait"
    btnClick.style.cursor = "wait"
    Const ForReading = 1
    Const TristateTrue = -1
    Const TemporaryFolder = 2
    Const WshHide = 0
    Dim wsh, fs, ts
    Dim strTempFile,strFile, strData
    Set wsh = CreateObject("Wscript.Shell")
    Set fs = CreateObject("Scripting.FileSystemObject")
    strTempFile = fs.BuildPath(fs.GetSpecialFolder(TemporaryFolder).Path, fs.GetTempName)
    strFile = fs.BuildPath(fs.GetSpecialFolder(TemporaryFolder).Path, "result.txt")
    wsh.Run "cmd.exe /c " & strCommand & " > " & DblQuote(strTempFile) & "2>&1", WshHide, True
    wsh.Run "cmd.exe /u /c Type " & DblQuote(strTempFile) & " > " & DblQuote(strFile) & "", WshHide, True
    Set ts = fs.OpenTextFile(strFile,ForReading,True,TristateTrue)
    strData = ts.ReadAll
    Output.Value = "Microsoft Windows [version 7.1 7631]" & vbcrlf &_
    "Copyright (c) 2009 Microsoft Corporation. All rights reserved." & vbcrlf & vbcrlf &_
    "C:\>"& strCommand & vbcrlf & strData
    ts.Close
    fs.DeleteFile strTempFile
    fs.DeleteFile strFile
    document.body.style.cursor = "default"
    btnClick.style.cursor = "default"
    btnClick.disabled = False   
End Sub
'**********************************************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'**********************************************************************************************
Sub OnClickButtonCopy()
    document.parentwindow.clipboardData.SetData "text", Output.Value
    MsgBox "The ouput result is copied to the clipboard !",vbInformation,Title
End Sub
'**********************************************************************************************
</script>
</head>
<body bgcolor="123456" text=Darkorange>
<hr>
<center><FONT SIZE="3"><B><I>Some examples of commands</I></B></FONT><BR>
<select style="background-color:lightblue" name="DropDown">
<option value="Tasklist">Tasklist</option>
<option value="CD %Programfiles%\Mozilla Firefox\ | Start Firefox.exe">CD %Programfiles%\Mozilla Firefox\ | Start Firefox.exe</option>
<option value="Tracert www.google.fr">Tracert www.google.fr</option>
<option value="Start iexplore">Start iexplore</option>
<option value="Start Notepad">Start Notepad</option>
<option value="Start Winword">Start Winword</option>
<option value="Explorer.exe /n,/e,/root,C:\Program Files">Explorer.exe /n,/e,/root,C:\Program Files</option>
<option value="Ipconfig">IpConfig</option>
<option value="Dir">Dir</option>
<option value="Ping www.yahoo.fr">Ping www.yahoo.fr</option>
<option value="Ping www.google.fr">Ping www.google.fr</option>
<option value="Taskkill /im iexplore.exe /f">Taskkill /im iexplore.exe /f</option>
</select>
<input type="button" onClick="Run_Cmd(DropDown.value)" value="Run this command">
<center><hr><B><I>Type your input command here</I></B><br>
<input type="text" Name="input" size="10"style="width:100%" value="Ping www.google.com" style="background-color:lightblue">
<input type="submit" name="btnClick" value="Run the input command line" onclick="Run_Cmd(input.value)"> 
<br><hr><B><I> The output result (readonly)</I></B><hr>
<textarea readonly id="Output" style="width:100%" rows="28" style="background-color:black; color:Darkorange">Microsoft Windows [version 7.1 7631]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\></textarea><input type="button" name="ButtonCopy" value="Copy the ouput result to the Clipboard" onclick="OnClickButtonCopy">
<hr></center>
</body>
</html>

这篇关于如何发送用户输入到cmd应用程序并获取输出结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆