我正在努力实现我在表单上有一个文本框控件和一个按钮控件。当点击输入到文本框控件中的任何内容时,我想将该数据发送到控制台应用程序,控制台应用程序又创建一个文本文件。我有它主要工作,但我无法从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
“#######################编辑###########
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)
答案 0 :(得分: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
为了防止窗口分裂你的参数,在
之前和之后连接一个引号字符Dim info As ProcessStartInfo = New ProcessStartInfo(file, """" & TextBox1.Text & """")
四个双引号字符表示包含单个双引号的字符串文字。