cStdIO Usage Examples
Example 1: Get System Info
vb
Private Sub GetSystemInfo()
Dim StdIO As New cStdIO
Dim Output As String
Dim ExitCode As Long
' Get network configuration
Output = StdIO.ExecuteCommand("ipconfig /all", 10000, "", ExitCode)
If ExitCode = 0 Then
txtOutput.Text = Output
Else
MsgBox "Failed to get network info"
End If
End SubExample 2: Git Operations
vb
Private Sub CheckGitStatus()
Dim StdIO As New cStdIO
Dim Result As String
Dim ExitCode As Long
' Check Git status
Result = StdIO.ExecuteCommand("git status", 5000, txtProjectPath.Text, ExitCode)
If ExitCode = 0 Then
' Parse status output
If InStr(Result, "nothing to commit") > 0 Then
lblStatus.Caption = "Working directory clean"
Else
lblStatus.Caption = "Uncommitted changes"
End If
txtDetails.Text = Result
Else
MsgBox "Git command execution failed"
End If
End SubExample 3: Batch Process Files
vb
Private Sub BatchConvertFiles()
Dim StdIO As New cStdIO
Dim FileList As String
Dim ExitCode As Long
Dim Files() As String
Dim i As Integer
' Get file list
FileList = StdIO.ExecuteCommand("dir /b *.txt", 5000, txtFolder.Text, ExitCode)
If ExitCode = 0 And Len(FileList) > 0 Then
Files = Split(FileList, vbCrLf)
For i = LBound(Files) To UBound(Files)
If Len(Files(i)) > 0 Then
' Process each file
ProcessFile txtFolder.Text & "\" & Files(i)
End If
Next i
End If
End SubExample 4: Network Test
vb
Private Sub PingHost()
Dim StdIO As New cStdIO
Dim Host As String
Dim Result As String
Dim ExitCode As Long
Host = txtHost.Text
' Execute ping command
Result = StdIO.ExecuteCommand("ping -n 4 " & Host, 20000, "", ExitCode)
txtResult.Text = Result
' Parse result
If InStr(Result, "Reply from") > 0 Then
lblStatus.Caption = "Host reachable"
lblStatus.ForeColor = vbGreen
Else
lblStatus.Caption = "Host unreachable"
lblStatus.ForeColor = vbRed
End If
End SubExample 5: Execute Task with Timeout
vb
Private Sub RunWithTimeoutControl()
Dim StdIO As New cStdIO
Dim Result As String
Dim ExitCode As Long
Dim StartTime As Long
StartTime = Timer
On Error GoTo TimeoutHandler
' Execute potentially time-consuming task (30 second timeout)
Result = StdIO.ExecuteCommand("data-processing.exe", 30000, "", ExitCode)
If ExitCode = 0 Then
MsgBox "Processing complete, time: " & (Timer - StartTime) & " seconds"
txtOutput.Text = Result
End If
Exit Sub
TimeoutHandler:
If Err.Number = 5 Then ' Assume timeout error number is 5
MsgBox "Task execution timeout (over 30 seconds)!", vbExclamation
Else
MsgBox "Execution error: " & Err.Description, vbCritical
End If
End SubExample 6: Command Line Tool Wrapper
vb
' Wrapper for FFmpeg call
Private Function RunFFmpeg(InputFile As String, OutputFile As String) As Boolean
Dim StdIO As New cStdIO
Dim Command As String
Dim Output As String
Dim ExitCode As Long
' Build command
Command = "ffmpeg -i """ & InputFile & """ """ & OutputFile & """
' Execute (60 second timeout)
Output = StdIO.ExecuteCommand(Command, 60000, "", ExitCode)
' Determine if successful
RunFFmpeg = (ExitCode = 0)
If Not RunFFmpeg Then
Debug.Print "FFmpeg error: " & Output
End If
End Function