467,213 Members | 1,103 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,213 developers. It's quick & easy.

How to execute a python script in .NET application

Hi,

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

Regards,
Chandra

Oct 6 '06 #1
  • viewed: 6349
Share:
5 Replies
hg
Chandra wrote:
Hi,

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

Regards,
Chandra
py**********@python.org ?
Oct 7 '06 #2
Chandra wrote:
Hi,

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

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Oct 7 '06 #3

Chandra wrote:
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;
}
}
}

Oct 7 '06 #4
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.

--
@-salutations

Michel Claveau
Oct 7 '06 #5
Thanks all of them, i used the command line process (executing the
script in cmd shell) method for executing python script.

Regards,
Chandra

Gerard Flanagan wrote:
Chandra wrote:
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;
}
}
}
Oct 9 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by spec | last post: by
4 posts views Thread by brad | last post: by
reply views Thread by srinivasan srinivas | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.