Python & C#: Is IronPython absolutely necessary? -


i'm c# programmer, have been left project leaves me 2 options:

  1. call out python script (saved .py file) , process return value, or...
  2. rewrite whole python script (involving 6 .py files in total) in c#.

naturally, option 2 major waste of time if can implement option 1. moreover, option 1 learning opportunity, while option 2 total geek copout.

so, question this: there way build c# process object trigger .py file's script , catch script's return value without using ironpython? don't have against possibly using ironpython, need solution possible, if can sidestep i.p. learning curve until have less urgent work do, optimal.

thanks.

use process.start run python script. in processstartinfo object, specify:

  • filename = path , file name of python script.

  • arguments = arguments want pass script.

  • redirectstandardoutput = true (and redirectstandarderror if needed)

  • useshellexecute = false

then process object on can things, in particular:

  • use process.standardoutput read python script’s output. could, example, call readtoend() on single string containing entire output, or call readline() in loop.

  • use process.exitcode read return code of script.

  • use process.waitforexit wait script finish.


Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -