简体   繁体   English

如何与用VB编写的基本cmd程序交互?

[英]How do I interact with a basic cmd program written in vb?

Thanks for all the help so far. 感谢到目前为止的所有帮助。 I was able to send the $Email variable to the stdio stream and receive it in the vb script. 我能够将$ Email变量发送到stdio流,并在vb脚本中接收它。 I am having a problem now with some of the code 我现在有些代码有问题

Option Strict On

Imports MySql.Data.MySqlClient
Imports System.Runtime.Serialization

Module jrConnect

    Sub Main(ByVal cmdArgs() As String)
        Dim returnValue As Integer = 0
        ' See if there are any arguments.
        If cmdArgs.Length > 0 Then
            For argNum As Integer = 0 To UBound(cmdArgs, 1)

                Console.Write("your email address is " & cmdArgs(argNum))
                If cmdArgs(argNum) <> "" Then
                    Dim email As String = cmdArgs(argNum)
                    Console.Write("Your email is " & email)
                End If
             Next argNum
        End If
        Dim cs As String = "*********"
        Dim conn As New MySqlConnection(cs)
        Dim entID As String

        Try
            conn.Open()
            Dim stm As String = "SELECT ***** FROM **** WHERE email =" & "'" & email & "'"
            Dim cmd As MySqlCommand = New MySqlCommand(stm, conn)
            Dim reader As MySqlDataReader = cmd.ExecuteReader()

            While reader.Read()
                entID = reader.GetString(0)
            End While
            reader.Close()

            Dim stm2 = "SELECT ***** FROM ****** WHERE ***** = " & entID
            Dim cmd2 As MySqlCommand = New MySqlCommand(stm2, conn)
            Dim reader2 As MySqlDataReader = cmd2.ExecuteReader()
            Dim counter As Integer = 0

            While reader2.Read() And counter < 3
                Console.WriteLine(reader2.GetString(0) & "%")
                counter = counter + 1
            End While
            reader.Close()

        Catch ex As MySqlException
        Finally
            conn.Close()
        End Try

    End Sub

End Module

It will print the email address correctly but when it calls the email address in the sql statement it states that "email is not declared" Is it changing the value of it in the "Next argNum" command? 它将正确打印电子邮件地址,但是当它在sql语句中调用电子邮件地址时,它指出“未声明电子邮件”是否在“ Next argNum”命令中更改了它的值? It only writes the email to console once. 它只将电子邮件写入控制台一次。 Here is my NSIS script if necessary as well. 如果需要,这也是我的NSIS脚本。

Outfile "test.exe"
Section
    SetOutPath $DOCUMENTS/
    Var /GLOBAL Email
    StrCpy $Email "spkelly8@gmail.com"

    nsExec::ExecToLog '"C:path/vbapp.exe" $Email'
    Pop $1
    Pop $2

    DetailPrint $1
    DetailPrint $2

SectionEnd

From the NSIS manual: 从NSIS手册中:

nsExec will execute command-line based programs and capture the output
without opening a dos box

Your console.Readline will expect some kind of interation and since its not connected to stdin/stdout, will fail. 您的console.Readline将发生某种交互,并且由于未连接到stdin / stdout,因此将失败。 Since you dont want the DOS box, and you want to send the email string via stdin rather than enter it manually, use ExecDos::exec 由于您不希望使用DOS框,并且希望通过stdin发送电子邮件字符串,而不是手动输入,因此请使用ExecDos::exec

ExecDos::exec /TIMEOUT=2000 "$DOCUMENTS\VBApp.exe" "$Email$\n"

Note the $ in front of \\n for NSIS to send a literal new line rather than the string \\n 请注意, \\n前面的$用于NSIS发送原义的新行而不是字符串\\n

You are trying to read from stdin but nsExec does not provide any data you can read from stdin. 您正在尝试从stdin中读取,但是nsExec不提供您可以从stdin中读取的任何数据。 Change the VB program to parse the commandline instead or use ExecDos or ExecCmd if your child process has to get the data from stdin... 更改VB程序以解析命令行,或者如果您的子进程必须从标准输入获取数据,则使用ExecDosExecCmd ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM