VB中引用cmd怎么查看返回信息
我做的VB程序用到了shell"cmd/cD:\a.exe"&filename的语句,可是a.exe执行后返回的信息(正常在cmd中打入命令行下面显示的东西)不知道怎么接...
我做的VB程序用到了
shell "cmd /c D:\a.exe " & filename
的语句,
可是a.exe执行后返回的信息(正常在cmd中打入命令行下面显示的东西)
不知道怎么接收?
就是把返回的信息放到text1.text中,有没有办法? 展开
shell "cmd /c D:\a.exe " & filename
的语句,
可是a.exe执行后返回的信息(正常在cmd中打入命令行下面显示的东西)
不知道怎么接收?
就是把返回的信息放到text1.text中,有没有办法? 展开
3个回答
展开全部
Private Declare Function CloseHandle Lib "Kernel32.dll" (ByVal Handle As Long) As Long
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Sub Form_Load()
Dim Pid As Long
Dim hProcess As Long
Dim FileName As String
Dim TmpFile As String
TmpFile = "c:\tmp.txt"
Pid = Shell("cmd /c D:\a.exe " & FileName & " > " & TmpFile) '将信息写到临时输出文件
hProcess = OpenProcess(2035711, 0, Pid) '// 用于等待SHELL 执行完成
WaitForSingleObject hProcess, -1 '// 用于等待SHELL 执行完成
CloseHandle hProcess '// 用于等待SHELL 执行完成
Open TmpFile For Binary As #1 '打开返回文件号
Dim Var As String
Var = String(LOF(1), 32) 'BUFF
Get #1, , Var '读到数据
Text1.Text = Var
Close #1 '关闭文件号
Kill TmpFile '删除临时文件
End Sub
也可以用管道,不过API函数和代码会更多一点,就这个把.
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Sub Form_Load()
Dim Pid As Long
Dim hProcess As Long
Dim FileName As String
Dim TmpFile As String
TmpFile = "c:\tmp.txt"
Pid = Shell("cmd /c D:\a.exe " & FileName & " > " & TmpFile) '将信息写到临时输出文件
hProcess = OpenProcess(2035711, 0, Pid) '// 用于等待SHELL 执行完成
WaitForSingleObject hProcess, -1 '// 用于等待SHELL 执行完成
CloseHandle hProcess '// 用于等待SHELL 执行完成
Open TmpFile For Binary As #1 '打开返回文件号
Dim Var As String
Var = String(LOF(1), 32) 'BUFF
Get #1, , Var '读到数据
Text1.Text = Var
Close #1 '关闭文件号
Kill TmpFile '删除临时文件
End Sub
也可以用管道,不过API函数和代码会更多一点,就这个把.
展开全部
回答这个问题好多次了 你看一下我的整理
http://hi.baidu.com/lijinfeng042/blog/item/851762ae8a40c5fcfbed5008.html
http://hi.baidu.com/lijinfeng042/blog/item/851762ae8a40c5fcfbed5008.html
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
text1 的 MultiLine 属性 True ,ScrollBars 属性 2
Set ws = CreateObject("wscript.shell")
ws.run "cmd /c D:\a.exe " & filename & ">tmp.txt", 0, True
Open "tmp.txt" For Input As #1
Do Until EOF(1)
Line Input #1, s
Text1.text = Text1.text & s & vbCrLf
Loop
Close #1
Kill "tmp.txt"
Set ws = CreateObject("wscript.shell")
ws.run "cmd /c D:\a.exe " & filename & ">tmp.txt", 0, True
Open "tmp.txt" For Input As #1
Do Until EOF(1)
Line Input #1, s
Text1.text = Text1.text & s & vbCrLf
Loop
Close #1
Kill "tmp.txt"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询