c# - How to display output of a python program in a text box located in a .aspx Web Form? -
i have simple python programme named hello.py
import sys def simple(): print "hello python" how display output of programme in text box located in web form of type .aspx.cs
protected void textbox1_textchanged(object sender, eventargs e) { textbox1.text = // output of hello.py asigned textbox1.text }
you have follow these steps accomplish this.
host python file in cgi, lets link http://localhost/cgi-bin/test.py , invoke using webclient , output. next code invoking url using webclient.
protected void textbox1_textchanged(object sender, eventargs e) { webclient client = new webclient(); string reply = client.downloadstring("http://localhost/cgi-bin/test.py"); // address = cgi hosted url textbox1.text = reply; } else
assumption: have python installed in windows system.
save python script file , abc.py. you can straight execute python script, using"c:\python26\python.exe" "abc.py". utilize in next step. using process execution, can execute above command c# , output. example- var proc = new process { startinfo = new processstartinfo { filename = "c:\python26\python.exe", arguments = "abc.py", useshellexecute = false, redirectstandardoutput = true, createnowindow = true } }; proc.start(); while (!proc.standardoutput.endofstream) { string line = proc.standardoutput.readline(); // line textbox1.text = line; } or - utilize link http://blog.luisrei.com/articles/flaskrest.html - shows , how create python code rest based thing, , can invoke straight rest api in asp.net code.
c# python asp.net
No comments:
Post a Comment