0

I want to pass a string from c# code to a.py file which is saved on my disk and execute the .py file. Is there a way to do it? this .py file simple python code. Moreover how to access that string in python? Any help on this would be great. Thanks

GBh
  • 343
  • 1
  • 4
  • 15
  • Maybe check out [IronPython](http://ironpython.net/) – Mike Christensen Sep 11 '13 at 19:51
  • @MikeChristensen Do I have to make any changes in the .py file?coz my .py file is a simple python application – GBh Sep 11 '13 at 19:57
  • 1
    Hard to say. If it's so simple, why not just pass in the string as a command line argument? – Mike Christensen Sep 11 '13 at 20:04
  • @MikeChristensen My application starts with execution of C# windows form, then it should invoke the python script simultaneously passing the string and the python script uses the string as a value for further execution. – GBh Sep 11 '13 at 20:08
  • Yea, worth trying out to see if it works right. You might get an annoying command prompt pop-up while the script is running, which is why I'd check out IronPython. You can just pass in the Python script as a string and run it inline. – Mike Christensen Sep 11 '13 at 20:10
  • 1
    To expand on Mike Christensen's comment see [this answer](http://stackoverflow.com/a/1469790/1322401) to Stack Overflow C# question "Run Command Prompt Commands". On the Python side you can use [`sys.argv`](http://docs.python.org/2/library/sys.html#sys.argv) to retrieve the command line argument. Note: the linked C# answer includes code to suppress the command window. – Steven Rumbalski Sep 11 '13 at 20:10

0 Answers0