Run c # application from python script

I just finished coding a decent model of disease transmission in C #. However, I'm pretty new to .NET and not sure how to do this. Currently, I just double-click on the .exe file, and the model imports the configuration setting from text files, does its job and outputs the results to a text file.

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

  • Run the simulation N times (N> 1000)
  • After each run, rename the output file and save (i.e. ../ output.txt → ./acc/outputN.txt)
  • Set, analysis and analysis of outputs
  • Print the result in some pure format (possibly in Excel)

Most of my programming experience to date has been in C / C ++ on Linux. I am pretty sure about the last two subjects; however, I have no idea how to proceed for the first two. Here are some specific questions that I would like to consult:

  • What is the easiest / best way to run my C # .exe from a python script?
  • Does anyone have any tips on the best way to work with the file system in Python on a Windows system?

Thanks!

+7
python filesystems subprocess simulation
source share
2 answers

With Python 2.6+, you should use the subprocess module: ( Docs )

 import subprocess for v in range(1000): cmdLine = r"c:\path\to\my\app.exe" subprocess.Popen(subprocess) subprocess.Popen(r"move output.txt ./acc/output-%d.txt" % (v)) 
+11
source share

The answer to your problems can be found in "os" in the python standard library. Documentation for performing various operations, such as file processing and initial processes, can be found here .

Process control (running your program in C #) can be found here , and file operations here .

EDIT: Actually, instead of the above process reference, you should use the subprocess module . p>

+3
source share

All Articles