Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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?

like image 339
Weng Fai Wong Avatar asked Nov 08 '10 07:11

Weng Fai Wong


People also ask

Can we use Python in asp net?

Dotnet 4.0 supports dynamic language interaction along with static languages for which CLR extends support. Currently supported languages are Ruby and Python.

Can .NET run Python?

Python.NET is a package that gives Python programmers nearly seamless integration with the . NET 4.0+ Common Language Runtime (CLR) on Windows and Mono runtime on Linux and OSX. Python for . NET provides a powerful application scripting tool for .

How do I run a .PY file in Python?

To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World! If everything works okay, after you press Enter , you'll see the phrase Hello World!


1 Answers

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

like image 142
Shekhar Avatar answered Oct 12 '22 20:10

Shekhar