0

感谢到目前为止的所有帮助。我能够将 $Email 变量发送到 stdio 流并在 vb 脚本中接收它。我现在遇到一些代码问题

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

它将正确打印电子邮件地址,但是当它在 sql 语句中调用电子邮件地址时,它指出“未声明电子邮件”它是否在“Next argNum”命令中更改了它的值?它只将电子邮件写入控制台一次。如有必要,这也是我的 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
4

2 回答 2

1

从 NSIS 手册:

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

console.Readline会期待某种交互,因为它没有连接到标准输入/标准输出,所以会失败。由于您不需要 DOS 框,并且您想通过标准输入发送电子邮件字符串而不是手动输入,请使用ExecDos::exec

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

注意$前面的\nNSIS 发送一个文字换行而不是字符串\n

于 2012-10-17T19:47:52.407 回答
0

您正在尝试从标准输入读取,但 nsExec 不提供您可以从标准输入读取的任何数据。如果您的子进程必须从标准输入中获取数据,请更改 VB 程序以解析命令行,或者使用ExecDosExecCmd ...

于 2012-10-17T19:53:19.207 回答