0

I have two projects one is written in .net and other in python. I have a function in python which creates record in database. When an insert event fires in my .net project (controller) I want to call that insert function in python. How can I do that?

Thanks in advance.

balakishore nadella
  • 511
  • 3
  • 7
  • 16

1 Answers1

0

What you want to do is execute a shell command from you C# code.

An example of how to do this can be seen here: Run Command Prompt Commands

Create your insert function in a separate python file, such as yourfile.py, then execute the following code using the appropriate python command:

string strCmdText;
strCmdText= "python yourfile.py";
System.Diagnostics.Process.Start("CMD.exe",strCmdText);

You'll need to make sure python is in your system path.

Community
  • 1
  • 1
  • There are lot of functions in my .py file. How to call a pirticular function? Also I need to send arguments to that function. – balakishore nadella Apr 06 '16 at 17:23
  • Either create a separate script which only contains the function, or do something like this http://stackoverflow.com/questions/3987041/python-run-function-from-the-command-line – SexyGiraffeMan Apr 06 '16 at 18:44
  • To pass a command line argument, simply separate them by spaces after you .py file in the command line and access them with sys.argv[index]. http://stackoverflow.com/questions/567879/how-can-i-process-command-line-arguments-in-python – SexyGiraffeMan Apr 06 '16 at 18:46