1

我要完成的工作是在表单上有一个文本框控件和一个按钮控件。当单击文本框控件中输入的任何内容时,我想将该数据发送到控制台应用程序,该应用程序进而创建一个文本文件。我大部分时间都在工作,但我无法获取从 Web 应用程序发送的数据。我该如何做到这一点?这是我到目前为止所拥有的。

这是我要发送到控制台应用程序的子程序:

    Public Sub send_to_console()

    Dim file As String = "C:\inetpub\wwwroot\TestConsoleApp\TestConsoleApp\bin\Debug\TestConsoleApp.exe"
    Dim info As ProcessStartInfo = New ProcessStartInfo(file, TextBox1.Text)

    Dim p As Process = Process.Start(info)

    End Sub

控制台应用程序代码:

 ublic Sub Main(ByVal args As String)

    Dim w As StreamWriter
    Dim filepath As String = "C:\xml_files\testFile.txt"

    Dim new_string As String
    new_string = "This has been completed on " & Date.Now

    If args = "" Then
        new_string = "No data entered on: " & Date.Now
    Else
        new_string = args & " " & Date.Now
    End If

    If System.IO.File.Exists(filepath) Then
        File.Delete(filepath)
    End If

    w = File.CreateText(filepath)

    w.WriteLine(new_string)
    w.Flush()
    w.Close()

End Sub

目前我收到一个错误:没有可访问的 Main

'#######################EDITS###########

  Dim file As String = "C:\inetpub\wwwroot\TestConsoleApp\TestConsoleApp\bin\Debug\TestConsoleApp.exe"
    Dim info As ProcessStartInfo = New ProcessStartInfo(file, TextBox1.Text)
    info.UseShellExecute = False

    Dim p As Process = Process.Start(info)
4

1 回答 1

0

main 接受一个字符串数组而不是字符串。

所以

Public Sub Main(ByVal args As String())
    .....

    If args.length < 1 Then
        new_string = "No data entered on: " & Date.Now
    Else
        new_string = args(0) & " " & Date.Now
    End If
    .....
End Sub

为了防止windows拆分你的参数,在前后连接一个引号字符

Dim info As ProcessStartInfo = New ProcessStartInfo(file, """" & TextBox1.Text & """")

四个双引号字符表示包含单个双引号的字符串文字。

于 2013-06-18T17:40:37.683 回答