cStdIO Standard Input/Output Component
Overview
cStdIO is a command-line execution component provided by the VBMAN framework, used to execute external command-line programs in VB6 and capture their standard output. Supports timeout control, working directory setting, and process exit code retrieval.
Features
- Capture Output - Fully capture command line standard output (STDOUT)
- Hide Window - Execute in background, no command line window shown
- Timeout Control - Can set execution timeout to prevent process deadlock
- Working Directory - Supports specifying working directory for command execution
- Exit Code Retrieval - Get process exit code to determine execution result
Quick Start
Simple Command Execution
vb
Dim StdIO As New cStdIO
Dim Output As String
Dim ExitCode As Long
' Execute command and get output
Output = StdIO.ExecuteCommand("ipconfig /all", 5000, "", ExitCode)
Debug.Print "Output: " & Output
Debug.Print "Exit code: " & ExitCodeExecute and Check Exit Code
vb
Private Sub RunGitStatus()
Dim StdIO As New cStdIO
Dim Result As String
Dim ExitCode As Long
Result = StdIO.ExecuteCommand("git status", 10000, "D:\\MyProject", ExitCode)
If ExitCode = 0 Then
Debug.Print "Git status: " & vbCrLf & Result
Else
Debug.Print "Command execution failed, exit code: " & ExitCode
End If
End SubTimeout Handling
vb
Private Sub RunWithTimeout()
Dim StdIO As New cStdIO
Dim Result As String
Dim ExitCode As Long
On Error GoTo ErrorHandler
' Set 5 second timeout
Result = StdIO.ExecuteCommand("long-running-task.exe", 5000, "", ExitCode)
Debug.Print Result
Exit Sub
ErrorHandler:
If InStr(Err.Description, "timeout") > 0 Then
MsgBox "Command execution timeout!", vbExclamation
End If
End SubTypical Use Cases
| Scenario | Example Command |
|---|---|
| System Info | ipconfig /all, systeminfo |
| Git Operations | git status, git log --oneline |
| File Operations | dir /s, findstr "keyword" *.txt |
| Network Test | ping 8.8.8.8, tracert baidu.com |
| Build | msbuild MyProject.sln |
Notes
- Timeout - Unit is milliseconds, default 10 seconds
- Hide Window - Command line window auto hidden, background execution
- Encoding Issue - Output text encoding depends on system default encoding
- Large Data - Large output may occupy more memory