从 python 脚本运行 C# 应用程序 [英] Run a C# application from python script

查看:43
本文介绍了从 python 脚本运行 C# 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚用 C# 编写了一个大小合适的疾病传播模型.但是,我对 .NET 还很陌生,不确定如何继续.目前我只是双击 .exe 文件,模型从文本文件中导入配置设置,执行它的操作,并将结果输出到文本文件中.

I've just about finished coding a decently sized disease transmission model in C#. However, I'm fairly new to .NET and am unsure how to proceed. Currently I just double-click on the .exe file and the model imports config setting from text files, does its thing, and outputs the results into a text file.

接下来我想做的是编写一个 Python 脚本来执行以下操作:

What I would like to do next is write a Python script to do the following:

  • 运行模拟 N 次 (N > 1000)
  • 每次运行后重命名输出文件并存储(即 ./output.txt -> ./acc/outputN.txt)
  • 聚合、解析和分析输出
  • 以某种干净的格式输出结果(可能是 excel)

迄今为止,我的大部分编程经验都是在 Linux 上使用 C/C++.我对最后两项相当有信心;但是,我不知道如何进行前两个.以下是一些我想提出建议的具体问题:

The majority of my programming experience to date has been in C/C++ on linux. I'm fairly confident about the last two items; however, I have no idea how to proceed for the first two. Here are some specific questions I'd like advice on:

  • 从 python 脚本运行我的 C# .exe 最简单/最好的方法是什么?
  • 有人对在 Windows 系统上使用 Python 进行文件系统操作的最佳方法有什么建议吗?

谢谢!

推荐答案

从 Python 2.6+ 开始,您应该使用 subprocess 模块:(文档)

As of Python 2.6+ you should be using the subprocess module: (Docs)

import subprocess

for v in range(1000):
    cmdLine = r"c:path	omyapp.exe"
    subprocess.Popen(subprocess)
    subprocess.Popen(r"move output.txt ./acc/output-%d.txt" % (v))

这篇关于从 python 脚本运行 C# 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆