[英]Self Hosted (Owin) based Asp.Net Web API on Windows 10 mobile phone
[英]ASP.NET OWIN self hosting console window couldn't start dynamically from a normal ASP.NET Web API Controller
我需要根據需要啟動OWIN自托管控制台應用程序。 這種需求是由一個單獨的ASP.NET Web API決定的,該API通常以調試模式托管在VS的IIS Express下。 但是,即使沒有收到錯誤,我也無法從這個決策ASP.NET Web API的內部提示命令窗口。 下面是我的測試代碼,它僅用於調用命令提示符,直接在我的決策Web API控制器內部編寫。
using (Process p = new Process())
{
// set start info
p.StartInfo = new ProcessStartInfo("cmd.exe")
{
RedirectStandardInput = true,
UseShellExecute = false,
WorkingDirectory = @"d:\"
};
// event handlers for output & error
p.OutputDataReceived += p_OutputDataReceived;
p.ErrorDataReceived += p_ErrorDataReceived;
// start process
p.Start();
// send command to its input
p.StandardInput.Write("dir" + p.StandardInput.NewLine);
//wait
p.WaitForExit();
}
所有應用程序都在同一台機器上。 截至上述代碼,在ASP.NET MVC控制器事件下運行時,我沒有得到任何輸出,盡管如果在控制台應用程序下運行,則相同的代碼為我提供了預期的命令窗口。
Is there any restriction to prompt command window under an ASP.NET Web API context?
我可以通過刪除“ RedirectStandardInput”來提示命令,如下所示。
try
{
using (Process p = new Process())
{
// set start info
p.StartInfo = new ProcessStartInfo("cmd.exe")
{
// RedirectStandardInput = true,
// UseShellExecute = false,
//WorkingDirectory = root + @"\Test"
};
// start process
p.Start();
p.WaitForExit();
p.Close();
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
保持該線程開放,就像有人為RedirectStandardInput = true的情況提示命令提供答案一樣
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.