Weng Fai Wong
Weng Fai Wong

Reputation: 640

How to run a .py (Python) file in ASP.NET?

I have a GetList.py file which consumes Web Service and saves the output in XML on the server.

How do I invoke GetList.py so it saves the output in XML on the server before displaying the XML output in .ASPX page?

Upvotes: 6

Views: 19779

Answers (2)

Shekhar
Shekhar

Reputation: 11788

You can create one batch file which contains call to python file and call that batch file from you .net application. To call batch file, you can use Process class. For example, suppose you have test.py file containing following code :

print "hello world"

then create one batch file (file having .bat extension) which has following contents :

python C:\test.py

Assuming you are using C#, and ur batchfile is stored in (C:\test.bat) you can use following code to invoke batch file

Process.Start("C:\test.bat");

You can have more details about Process class here

Upvotes: 10

Rafe Kettler
Rafe Kettler

Reputation: 76955

If your server has a Python interpreter installed, use that. (It's usually in /usr/bin/python)

If it doesn't (and it probably doesn't, since you use .NET), use IronPython. It's based on .NET and works very nicely with ASP.NET. Fair warning: if your GetList.py script uses parts of the CPython standard library that haven't been implemented in IronPython, you might have to change the script. See this article to get a basic intro to IronPython and see how it fits in with .NET.

Upvotes: 6

Related Questions