【问题标题】:How to access data from inside an Azure VM?如何从 Azure VM 内部访问数据?
【发布时间】:2016-08-25 21:10:43
【问题描述】:

假设我有一个在 MS-Azure 上运行的 VM(Windows)。 假设我在该 VM 上有程序 Y 和 Z,它们正在记录一些关键数据。假设我在 VM 中还有一个程序 X,它接受一些参数并根据过滤器返回一些关键数据。

现在,我正在构建一个前端 webapp,一个 ASP.NET 网站,上面提到的 VM 的所有者可以登录并查看程序 X 可以提供的数据。

我已经在 VM 中运行了我的日志程序并安装了程序 X。如何访问 VM 内的可执行文件,将参数传递给它,运行它并将结果返回给我?这是可行的吗?有人可以建议我如何实现这一目标吗?

谢谢。

【问题讨论】:

    标签: c# asp.net azure virtual-machine azure-virtual-machine


    【解决方案1】:

    如果您的程序 X 不涉及 GUI,您可以尝试在 PS Remote Session 上运行它。这是一个很好的guide,关于如何配置 powershell 遥控器。

    另外,这里是article关于需要在防火墙上打开的端口。

    默认情况下,PowerShell 将使用以下端口进行通信 (它们与 WinRM 是相同的端口)

    TCP/5985 = HTTP

    TCP/5986 = HTTPS

    如果涉及 GUI,据我所知,唯一的解决方案是使用 RDP 远程连接到 VM。

    此外,在 Internet 上公开 WinRM 或 RDP 端口并不是一个好主意。我建议你在 Azure 上创建一个 VPN 并使用 WinRM 或 RDP over VPN。

    【讨论】:

      【解决方案2】:

      您可以使用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();
      

      复制自: run console application in C# with parameters

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-04-28
        • 1970-01-01
        • 2021-06-07
        • 2018-09-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-27
        相关资源
        最近更新 更多