怎么才能在VB.NET中向控制台输出命令行,并且将返回的信息在VB中获得啊?

kinglee1220 2008-05-14 08:56:02
具体情况:我要在VB.NET中调用PsTools工具,执行我要执行的控制语句,之后将获得的信息对应的保存到数据库中。
各位谁有这方面的经验给江将怎么弄,拜谢了!
...全文
1066 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
itcoco 2008-05-17
  • 打赏
  • 举报
回复
mark 学习
pxb0420 2008-05-16
  • 打赏
  • 举报
回复
MSDN提供的例子:

compiler.StartInfo.FileName = "csc.exe"
compiler.StartInfo.Arguments = "/r:System.dll /out:sample.exe stdstr.cs"
compiler.StartInfo.UseShellExecute = False
compiler.StartInfo.RedirectStandardOutput = True
compiler.Start()

Console.WriteLine(compiler.StandardOutput.ReadToEnd())

compiler.WaitForExit()


pxb0420 2008-05-16
  • 打赏
  • 举报
回复
学习了。谢谢

楼主也很强吗:)
kinglee1220 2008-05-15
  • 打赏
  • 举报
回复
这个问题解决了!嗬嗬谢谢楼上了!
Dim myProcess As Process = New Process()
  Dim s As String
  myProcess.StartInfo.FileName = "cmd.exe"
  myProcess.StartInfo.UseShellExecute = False
  myProcess.StartInfo.CreateNoWindow = True
  myProcess.StartInfo.RedirectStandardInput = True
  myProcess.StartInfo.RedirectStandardOutput = True
  myProcess.StartInfo.RedirectStandardError = True
  myProcess.Start()
  Dim sIn As StreamWriter = myProcess.StandardInput
  sIn.AutoFlush = True
  Dim sOut As StreamReader = myProcess.StandardOutput
  Dim sErr As StreamReader = myProcess.StandardError
  sIn.Write("dir c:\Windows\system32\*.com" & _
  System.Environment.NewLine)
  sIn.Write("exit" & System.Environment.NewLine)
  s = sOut.ReadToEnd()
  If Not myProcess.HasExited Then
  myProcess.Kill()
  End If
  MessageBox.Show("The 'dir' command window was " & _
  closed at: " & myProcess.ExitTime & "." & _
  System.Environment.NewLine & "Exit Code: " & _
  myProcess.ExitCode)
  sIn.Close()
  sOut.Close()
  sErr.Close()
  myProcess.Close()
  MessageBox.Show(s)
清晨曦月 元老 2008-05-14
  • 打赏
  • 举报
回复
。。如果是自己写整个功能可以写一个控制台应用程序,而如果。。。。。调用其他的CMD程序,则可以用管道。
楼主可以自己查一下,实现起来SO EZ

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧