Hyper-V PowerShell - 运行 Linux VM 中的 bash 命令并获取输出
Hyper-V PowerShell - Run a bash command in Linux VM and get output
假设你有
Windows 使用 Hyper-V 和 PowerShell 5.1 的服务器。您可以添加和使用任何 PowerShell 模块,例如 "Hyper-V".
Linux 虚拟机。它是通用的,因此您不能安装不常见的应用程序,例如 PowerShell Core。
现在您正在使用 (1) Hyper-V,您可以在其中 运行 PowerShell 脚本。
问题。您如何在 (2) Linux VM 上 运行 Bash 命令并使用该 PowerShell 获取它的输出来自 Hyper-V?
我相信这个问题等同于 create 和 运行 问题。ps1 that 运行s bash /tmp/linux.sh在 Linux VM 中并获得所需的输出 100,其中 /tmp/linux.sh 显示在图像中。
| | Hyper-V (host) | Linux VM (guest) |
|----------|-----------------|------------------|
| IPv4 | 10.0.0.1 | 10.0.0.200 |
| hostname | hyperv | vm |
| Username | userH | userL |
| Password | passwordH | passwordL |
| Script | C:\question.ps1 | /tmp/linux.sh |
召回。 在 Linux VM 中,您有 /tmp/linux.sh
:
#!/bin/bash
val=100
echo "$val"
exit $?
回答(已确认)。将 PuTTY 存储在 Windows Hyper-V 主机中。
Tips. PuTTY 便携就够了:https://portableapps.com.
假设您已将 PuTTY Portable 存储在 C:\PortableApps\PuTTYPortable。
创建 PowerShell 脚本文件C:\Users\userH\Desktop\question.ps1
C:\PortableApps\PuTTYPortable\App\putty\PLINK.EXE 10.0.0.200 -l userL -pw passwordL -batch bash /tmp/linux.sh
^^ 将此行放在此 PowerShell 脚本文件的某处。
在 PowerShell 中,运行 脚本文件 question.ps1
:
PS C:\> & "C:\Users\userH\Desktop\question.ps1"
100
PS C:\>
假设你有
Windows 使用 Hyper-V 和 PowerShell 5.1 的服务器。您可以添加和使用任何 PowerShell 模块,例如 "Hyper-V".
Linux 虚拟机。它是通用的,因此您不能安装不常见的应用程序,例如 PowerShell Core。
现在您正在使用 (1) Hyper-V,您可以在其中 运行 PowerShell 脚本。
问题。您如何在 (2) Linux VM 上 运行 Bash 命令并使用该 PowerShell 获取它的输出来自 Hyper-V?
我相信这个问题等同于 create 和 运行 问题。ps1 that 运行s bash /tmp/linux.sh在 Linux VM 中并获得所需的输出 100,其中 /tmp/linux.sh 显示在图像中。
| | Hyper-V (host) | Linux VM (guest) |
|----------|-----------------|------------------|
| IPv4 | 10.0.0.1 | 10.0.0.200 |
| hostname | hyperv | vm |
| Username | userH | userL |
| Password | passwordH | passwordL |
| Script | C:\question.ps1 | /tmp/linux.sh |
召回。 在 Linux VM 中,您有 /tmp/linux.sh
:
#!/bin/bash
val=100
echo "$val"
exit $?
回答(已确认)。将 PuTTY 存储在 Windows Hyper-V 主机中。
Tips. PuTTY 便携就够了:https://portableapps.com.
假设您已将 PuTTY Portable 存储在 C:\PortableApps\PuTTYPortable。
创建 PowerShell 脚本文件C:\Users\userH\Desktop\question.ps1
C:\PortableApps\PuTTYPortable\App\putty\PLINK.EXE 10.0.0.200 -l userL -pw passwordL -batch bash /tmp/linux.sh
^^ 将此行放在此 PowerShell 脚本文件的某处。
在 PowerShell 中,运行 脚本文件 question.ps1
:
PS C:\> & "C:\Users\userH\Desktop\question.ps1"
100
PS C:\>