我正在使用这个库连接到我运行和运行的 Linux 命令,但有些命令有问题
例如,我在运行这些命令时遇到问题:
顶部和顶部 -n 1
错误:未设置TERM环境变量
private void button2_Click(object sender, EventArgs e)
{
Renci.SshNet.SshClient sshClient = new Renci.SshNet.SshClient("192.168.150.128", "reza", "1");
sshClient.Connect();
var command = sshClient.RunCommand("top");
var line = command.Result.Split('\n');
List<ServerStatusCpu> serverstatus = new List<ServerStatusCpu>();
for (int i = 3; i < line.Length - 1; i++)
{
var li = line[i];
var words = li.Split(' ');
List<string> fillterwords = new List<string>();
foreach (var w in words)
{
if (w != "")
{
fillterwords.Add(w);
}
}
ServerStatusCpu serverStatus = new ServerStatusCpu();
serverStatus.Time = fillterwords[0];
serverStatus.TimeType = fillterwords[1];
serverStatus.Name = fillterwords[2];
serverStatus.UserCpuTime = float.Parse(fillterwords[3].Replace("%", ""));
serverStatus.UserNiceCpuTime = float.Parse(fillterwords[4].Replace("%", ""));
serverStatus.SystemCpuTime = float.Parse(fillterwords[5].Replace("%", ""));
serverStatus.IoWaitCpuTime = float.Parse(fillterwords[6].Replace("%", ""));
serverStatus.IrqCpuTime = float.Parse(fillterwords[7].Replace("%", ""));
serverStatus.SoftwareIrqCpuTime = float.Parse(fillterwords[8].Replace("%", ""));
serverStatus.StealCpuTime = float.Parse(fillterwords[9].Replace("%", ""));
serverStatus.GuestCpuTime = float.Parse(fillterwords[10].Replace("%", ""));
serverStatus.IdleCpuTime = float.Parse(fillterwords[11].Replace("%", ""));
serverstatus.Add(serverStatus);
}
dataGridView1.DataSource = serverstatus;
}
class ServerStatusCpu
{
public class ServerStatusCpu
{
public string Time { get; set; }
public string TimeType { get; set; }
public string Name { get; set; }
public float UserCpuTime { get; set; }
public float SystemCpuTime { get; set; }
public float UserNiceCpuTime { get; set; }
public float IdleCpuTime { get; set; }
public float IoWaitCpuTime { get; set; }
public float IrqCpuTime { get; set; }
public float SoftwareIrqCpuTime { get; set; }
public float StealCpuTime { get; set; }
public float GuestCpuTime { get; set; }
}
}