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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

There are lot of functions in my .py file. How to call a pirticular function? Also I need to send arguments to that function.
Either create a separate script which only contains the function, or do something like this stackoverflow.com/questions/3987041/…
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]. stackoverflow.com/questions/567879/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.