うまく作れた?ので、メモ
要件:
バッチ実行した結果(Stdout)を強奪してStringに落とすこと
Public Class SharedFunction
Public Shared Function ExecuteBatch(ByVal exeFilePath As String, _
ByVal exeArg As String, Optional ByVal workingDir As String = "") As String
'プロセスの作成
Dim pcInfo As New ProcessStartInfo
pcInfo.FileName = exeFilePath
pcInfo.Arguments = exeArg
pcInfo.CreateNoWindow = True
pcInfo.WorkingDirectory = workingDir
'標準出力を強奪準備
pcInfo.StandardOutputEncoding = Encoding.UTF8
pcInfo.RedirectStandardOutput = True
pcInfo.UseShellExecute = False
'バッチの実行
Dim pc As New Process
pc.StartInfo = pcInfo
pc.Start()
pc.WaitForExit()
'標準出力を強奪
Dim stdOut = pc.StandardOutput
'結果を返す
Return stdOut.ReadToEnd
End Function
End Class
でもって、
Public Function GetVersion() As String
Dim retString As String
Dim batchGo = "8g"
retString = ExecuteBatch(batchGo, "-V")
Return retString
End Function
とすると、「8g」(Go言語の386用コンパイラ)のバージョン(スイッチ -V)が取得できるはず。
というわけで、強奪成功v