I am trying to redirect command line output to a list box in a vba macro, and I've found some code that I think might point me in the right direction, but I keep on getting the same error. When I use this code
Function ReadCmdOutput(ByVal applicationName As String,
Optional ByVal applicationArgs As String = "", Optional ByVal
workingDirectory As String = "", Optional ByVal showWindow As Boolean
= False) As String
Try
Dim processObj As New Process
processObj.StartInfo.UseShellExecute = False
processObj.StartInfo.RedirectStandardOutput = True
processObj.StartInfo.FileName = applicationName
processObj.StartInfo.Arguments = applicationArgs
processObj.StartInfo.WorkingDirectory = workingDirectory
If showWindow = True Then
processObj.StartInfo.CreateNoWindow = False
Else
processObj.StartInfo.CreateNoWindow = True
End If
processObj.Start()
processObj.WaitForExit()
Return processObj.StandardOutput.ReadToEnd
Catch ex As Exception
Return ""
End Try
End Function
It gives me the error in the title and highlights the first declaration line.
Question: What does it take to define a new "process".
Bonus points: Helping me with command line output redirect!
This can't be VBA since there is no Try/Catch in VBA or return
statements. This looks like VB.NET. Either way, the compiler is telling you that there is currently no reference to any dll that contains the process object.
If this is VB.NET, you need to add Imports System.Diagnostics
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.