6

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?

2 Answers 2

10

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

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

5 Comments

Is it not possible to call the test.py directly from C#?
hi @Shekhar , this method is very slow as it is initiating the command prompt. It is taking more than 5 minutes, please suggest a faster method
@pyd, If you execute your batch file/python file manually (without C# program based invocation) then how long does it take?
Almost same time, in c# code also will initiate the CMD process right? Is there any other way to invoke python script from a c# exe or asp.net code. Please help
It's been really long time I have not touched anything related to .Net, I work on Big Data, Java and Scala realted stuff nowadays so I am afraid I won't be able to help here. Sorry.
6

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.

1 Comment

This is a good solution when I host it on VPS myself eventually. Right now I've decided to run .Py file(which outputs and saves and XML file) on a cheaper Web Server and on my .Net Web Server I would retrieve the XML file.

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.