vb.net プロジェクトで python プログラムからの出力を読み取ったり使用したりしようとしていますが、結果が得られません。私が見たいのは、python プログラムが実行され (最初は単独で)、すべての出力がテキスト ボックスにリダイレクトされることです。
これに関する他のいくつかの投稿を見てきましたが、空白の出力しか得られないため、何かが欠けているか、何かを理解していません。パブリック クラス Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim PythonPath = "C:\Python27\"
Dim strPath As String = Application.StartupPath
MessageBox.Show(PythonPath & "python.exe """ & strPath & "\Resources\import_logs.py"" ")
Dim start_info As New ProcessStartInfo(TextBox1.Text)
' Make the process and set its start information.
Dim process As New Process()
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
process.StartInfo.FileName = PythonPath & "\python.exe"
process.StartInfo.Arguments = """" & strPath & "\resources\import_logs.py"""""
process.StartInfo.UseShellExecute = False
process.StartInfo.CreateNoWindow = True
process.StartInfo.RedirectStandardOutput = True
'process.StartInfo.RedirectStandardError = True
AddHandler process.OutputDataReceived, AddressOf proccess_OutputDataReceived
process.Start()
process.BeginOutputReadLine()
End Sub
Public Sub proccess_OutputDataReceived(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
On Error Resume Next
' output will be in string e.Data
' modify TextBox.Text here
'Server_Logs.Text = e.Data ` Does not display anything in textbox
MsgBox(e.Data) 'It works but I want output in text box field
End Sub
End Class
最終的には Python スクリプトに引数を渡す予定です。その際に使用できるフィードバックを取得したいので (エラーをデータベースに挿入する、完了時にメールを送信するなど)、プロセスをキャプチャしてもらいたいと考えています。最後にデータダンプだけではありません。
どんな助けでも大歓迎です。