2个回答
展开全部
给你个简单方便的程序。
创建如下控件:
Command1,Text1,Text2,Timer1.
设置Text2.MultiLine=True。(一定!)
在Text1中输入Dos命令,单击按钮,稍候片刻,在Text2中显示结果。
===========================
Const p = "d:\a.txt"
Private Sub Command1_Click()
Text2.Text = ""
Timer1.Enabled = False
Dim t As String
Shell "cmd /c" & Text1.Text & ">" & p
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
Open p For Input As 1
Do While EOF(1) = False
Line Input #1, t
Text2.Text = Text2.Text + t
Loop
Close 1
End Sub
创建如下控件:
Command1,Text1,Text2,Timer1.
设置Text2.MultiLine=True。(一定!)
在Text1中输入Dos命令,单击按钮,稍候片刻,在Text2中显示结果。
===========================
Const p = "d:\a.txt"
Private Sub Command1_Click()
Text2.Text = ""
Timer1.Enabled = False
Dim t As String
Shell "cmd /c" & Text1.Text & ">" & p
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
Open p For Input As 1
Do While EOF(1) = False
Line Input #1, t
Text2.Text = Text2.Text + t
Loop
Close 1
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const PROCESS_QUERY_INFORMATION = &H400
Private Const STILL_ALIVE = &H103
Private Sub Command1_Click()
'On Error Resume Next
Dim tmp As String '临时文件名
Dim tmp1 As String '临时文件内容
Dim strCommand As String 'DOS命令集
Dim pid As Long, hProcess As Long, i As Long
Text2 = ""
strCommand = Trim(Replace(Text1, vbCrLf, " & "))
If strCommand = "" Then Exit Sub
tmp = "c:\1.txt"
pid = Shell("cmd.exe /c " & strCommand & ">" & tmp, vbHide) ' vbHide)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid)
Do
Call GetExitCodeProcess(hProcess, ExitCode)
DoEvents
Loop While ExitCode = STILL_ALIVE
If Dir(tmp) <> "" Then
Open tmp For Input As #1
While EOF(1) = False
Line Input #1, tmp1
Text2 = Text2 + tmp1 + vbCrLf
Wend
Close #1
Kill tmp
End If
End Sub
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const PROCESS_QUERY_INFORMATION = &H400
Private Const STILL_ALIVE = &H103
Private Sub Command1_Click()
'On Error Resume Next
Dim tmp As String '临时文件名
Dim tmp1 As String '临时文件内容
Dim strCommand As String 'DOS命令集
Dim pid As Long, hProcess As Long, i As Long
Text2 = ""
strCommand = Trim(Replace(Text1, vbCrLf, " & "))
If strCommand = "" Then Exit Sub
tmp = "c:\1.txt"
pid = Shell("cmd.exe /c " & strCommand & ">" & tmp, vbHide) ' vbHide)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid)
Do
Call GetExitCodeProcess(hProcess, ExitCode)
DoEvents
Loop While ExitCode = STILL_ALIVE
If Dir(tmp) <> "" Then
Open tmp For Input As #1
While EOF(1) = False
Line Input #1, tmp1
Text2 = Text2 + tmp1 + vbCrLf
Wend
Close #1
Kill tmp
End If
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询