从Web调用控制台应用程序

时间:2013-07-02 05:54:31

标签: vb.net console-application

我们可以从Web应用程序调用并将参数传递给控制台应用程序吗?

例如我有一个Web应用程序有3个文本框。第一个和第二个文本框的值为10和20,第三个文本框用于从控制台应用程序返回值。

用于添加这两个值并返回结果的控制台应用程序。

如何通过vb.net代码实现任何一个帮助?

1 个答案:

答案 0 :(得分:1)

只需使用Process类来启动流程并读取输出以填充第三个文本框值:

Dim proc = New Process() With { _
        .StartInfo = New ProcessStartInfo() With { _
        .FileName = "program.exe", _
        .Arguments = "your command line arguments if needed", _
        .UseShellExecute = False, _
        .RedirectStandardOutput = True, _
        .CreateNoWindow = True _
        } _
   }

   proc.Start()

   'After process starts, you read the output

   While Not proc.StandardOutput.EndOfStream
       ' do something with line (append a stringbuilder for example)
       Dim line As String = proc.StandardOutput.ReadLine()
   End While