我们说我在MS-Azure上运行了一个VM(Windows)。 假设我在该VM上有程序Y和Z,它们正在记录一些关键数据。让我们说我在VM中也有一个程序X,它接受一些参数并根据过滤器返回一些关键数据。
现在,我正在构建一个前端webapp,一个ASP.NET网站,上面提到的VM的所有者可以登录并查看程序X可以提供的数据。
我已经在VM中安装了我的日志程序并安装了程序X.如何访问VM内部的exectuble,将参数传递给它,运行它并将结果返回给我?这可行吗?有人可以建议我如何实现这个目标吗?
感谢。
答案 0 :(得分:0)
如果您的程序X不涉及GUI,您可以尝试在PS远程会话上运行它。这是关于如何配置powershell远程的好guide。
此外,这里有关于端口需要在防火墙上打开的article。
默认情况下,PowerShell将使用以下端口进行通信 (它们与WinRM的端口相同)
TCP / 5985 = HTTP
TCP / 5986 = HTTPS
如果它涉及GUI,据我所知,唯一的解决方案是使用RDP远程连接到VM。
此外,在互联网上公开WinRM或RDP端口并不是一个好主意。我建议你在Azure上创建一个VPN,并通过VPN使用WinRM或RDP。
答案 1 :(得分:-1)
您可以使用System.Diagnostic.Process
类运行另一个可执行文件:
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "X.exe";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();