Python & C#: Is IronPython absolutely necessary? -
i'm c# programmer, have been left project leaves me 2 options:
- call out python script (saved .py file) , process return value, or...
- 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 (andredirectstandarderror
if needed)useshellexecute
= false
then process
object on can things, in particular:
use
process.standardoutput
read python script’s output. could, example, callreadtoend()
on single string containing entire output, or callreadline()
in loop.use
process.exitcode
read return code of script.use
process.waitforexit
wait script finish.
Comments
Post a Comment