码迷,mamicode.com
首页 > Windows程序 > 详细

C#调用exe

时间:2020-07-07 12:57:32      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:env   lse   退出   空格   one   standard   cto   tail   argument   


namespace WpfTest2
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
//string debugPath = System.Environment.CurrentDirectory; //此c#项目的debug文件夹路径
string pyexePath = @"C:\Users\user\Desktop\test\dist\main.exe";
//python文件所在路径,一般不使用绝对路径,此处仅作为例子,建议转移到debug文件夹下

Process p = new Process();
p.StartInfo.FileName = pyexePath;//需要执行的文件路径
p.StartInfo.UseShellExecute = false; //必需
p.StartInfo.RedirectStandardOutput = true;//输出参数设定
p.StartInfo.RedirectStandardInput = true;//传入参数设定
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = "2 3";//参数以空格分隔,如果某个参数为空,可以传入””
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();//关键,等待外部程序退出后才能往下执行}
Console.Write(output);//输出
p.Close();
}
}

————————————————
版权声明:本文为CSDN博主「武林大皮虾」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_42063091/article/details/82418630

C#调用exe

标签:env   lse   退出   空格   one   standard   cto   tail   argument   

原文地址:https://www.cnblogs.com/qq2806933146xiaobai/p/13259855.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!