码迷,mamicode.com
首页 > 其他好文 > 详细

CMD 调用返回

时间:2016-04-30 22:09:17      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:

    Public Function ExecuteCmd(cmdstr As String)
        Dim startInfo As New ProcessStartInfo("cmd.exe")
        With startInfo
            .Arguments = "/C " + cmdstr
            .RedirectStandardError = True
            .RedirectStandardOutput = True
            .UseShellExecute = False
            .CreateNoWindow = True
        End With
 
        Dim p As Process = Process.Start(startInfo)
        Dim strOutput As String = p.StandardOutput.ReadToEnd()
        Dim strError As String = p.StandardError.ReadToEnd()
 
        p.WaitForExit()
        Dim rsstr As String = ""
        If (strOutput.Length <> 0) Then
            rsstr = strOutput
        ElseIf (strError.Length <> 0) Then
            rsstr = strError
        End If
        rs.Text = rsstr
        If Not InStr(rsstr, "错误") > 0 Then
            IO.File.AppendAllText("Succeed.txt", txt_id.Text & txt_rs.Text & "," & txt_ps.Text & vbCrLf)
        End If
        btn.Enabled = True
        Return rsstr
 

    End Function  




CMD 调用返回

标签:

原文地址:http://www.cnblogs.com/dvmu/p/5449494.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!