How to execute a python script in .NET application

C

Chandra

Hi,

Is there a way to execute a python script(file) in ASP.NET application
(programmatically)??

Regards,
Chandra
 
S

Steve Holden

Chandra said:
Hi,

Is there a way to execute a python script(file) in ASP.NET application
(programmatically)??
Probably use IronPython, I should think.

regards
Steve
 
G

Gerard Flanagan

Chandra said:
Hi,

Is there a way to execute a python script(file) in ASP.NET application
(programmatically)??

Regards,
Chandra


I thought IIS would prevent this, but the following works for me at
home (ASP.NET 1.1). A production setup may be a different matter.

using System.Diagnostics

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(object sender, System.EventArgs e)
{
ProcessStartInfo startInfo;
Process process;
string directory = @"c:\python\python24\Lib\site-packages";
string script = "test.py";

startInfo = new ProcessStartInfo("python");
startInfo.WorkingDirectory = directory;
startInfo.Arguments = script;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;

process = new Process();
process.StartInfo = startInfo;
process.Start();

string s;
while ((s = process.StandardOutput.ReadLine()) != null)
{
Label1.Text += s;
}
}
}
 
M

MC

Hi!

dotNET can use (call) COM-servers

In pywin, there are exemple of COM-server, in Python, who can run
(on-the-fly) Python code.

This give a way for run Python's scripts from dotNET, Excel, Word,
Internet-Explorer (HTA), C#, etc. I have try all these things, with
success.
 
C

Chandra

Thanks all of them, i used the command line process (executing the
script in cmd shell) method for executing python script.

Regards,
Chandra
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top