Chandra wrote:
Hi,
Is there a way to execute a python script(file) in ASP.NET application
(programmatical ly)??
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.Diagnost ics
public class WebForm1 : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Labe l Label1;
private void Page_Load(objec t sender, System.EventArg s e)
{
ProcessStartInf o startInfo;
Process process;
string directory = @"c:\python\pyt hon24\Lib\site-packages";
string script = "test.py";
startInfo = new ProcessStartInf o("python");
startInfo.Worki ngDirectory = directory;
startInfo.Argum ents = script;
startInfo.UseSh ellExecute = false;
startInfo.Creat eNoWindow = true;
startInfo.Redir ectStandardOutp ut = true;
startInfo.Redir ectStandardErro r = true;
process = new Process();
process.StartIn fo = startInfo;
process.Start() ;
string s;
while ((s = process.Standar dOutput.ReadLin e()) != null)
{
Label1.Text += s;
}
}
}