日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

c中获取python控制台输出_在真实的tim中用C捕获控制台python打印

發(fā)布時間:2025/3/8 python 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c中获取python控制台输出_在真实的tim中用C捕获控制台python打印 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我正在嘗試從C創(chuàng)建一個python進(jìn)程,并從python腳本獲取打印結(jié)果。在

這就是我的C代碼:namespace ConsoleApp1

{

public class CreateProcess

{

public String PythonPath { get; set; }

public String FilePath { get; set; }

public String Arguments { get; set; }

public Process process;

public void run_cmd()

{

this.process = new Process();

ProcessStartInfo start = new ProcessStartInfo

{

FileName = this.PythonPath,

Arguments = string.Format("{0} {1}", this.FilePath, this.Arguments),

UseShellExecute = false,

RedirectStandardOutput = true,

};

this.process.StartInfo = start;

this.process.OutputDataReceived += p_OutputDataReceived;

this.process.Start();

this.process.BeginOutputReadLine();

//this.process.WaitForExit();

}

void p_OutputDataReceived(object sender, DataReceivedEventArgs e)

{

Console.Write(e.Data);

}

}

class Program

{

static void Main(string[] args)

{

CreateProcess test = new CreateProcess();

test.PythonPath = "mypathtopython.exe";

test.FilePath = "pythonfilename";

test.Arguments = "arg1 arg2 arg3";

test.run_cmd();

}

}

}

當(dāng)我刪除WaitForExit()方法時,會出現(xiàn)以下錯誤:

^{2}$

當(dāng)我保留它時,它可以工作,但是當(dāng)python進(jìn)程停止運(yùn)行時(這是意料之中的),輸出將打印到我的控制臺。我希望它能實時發(fā)生…知道我哪里做錯了嗎?在

這在python中可能是個問題,而不是在C中,但我不確定如何修復(fù)它。這是我的python測試腳本:import time

import os

import sys

print("First example")

time.sleep(10)

print("Arguments given:",sys.argv)

我也試過用系統(tǒng)stdout.flush()但是沒有成功。在

總結(jié)

以上是生活随笔為你收集整理的c中获取python控制台输出_在真实的tim中用C捕获控制台python打印的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。