Note that there are some explanatory texts on larger screens.

plurals
  1. POExecute a server side program asynchronously with an asp.net mvc4 app
    text
    copied!<p>is it possible to execute a server side program and get the output asynchronously.</p> <p>i have this code that doing the job but synchronously:</p> <p>suppose a c# program "program.exe" like this :</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace testconsole { class Program { static void Main(string[] args) { for (int k = 0; k &lt; 10; k++ )Console.WriteLine(k); } } } </code></pre> <p>some view in the asp.net app like this :</p> <pre><code>&lt;script &gt; function go() { var options = { url: '/excute', type: 'GET', dataType: 'json' } //make call $.ajax(options) .then(function (data) { console.log(data); }); } &lt;/script&gt; &lt;input type="submit" onclick="go();" value="Go"&gt; </code></pre> <p>and the <em>excute</em> controller looks like this :</p> <pre><code>namespace myApp.Controllers { public class ExecuteController : Controller { // // GET: /Execute [HttpGet] public JsonResult Index() { Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = "program.exe"; p.Start(); string output = p.StandardOutput.ReadToEnd(); p.WaitForExit(); return Json(new { op = output }, JsonRequestBehavior.AllowGet); } } } </code></pre> <p>All this is working fine, But ... from the client have to wait till the end of the program to display its outputs, is there any way to get those outputs as soon as they r created?</p> <p>im sur i need to make some changes in the controller to make it possible, but how ???</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload