gpt4 book ai didi

c# - plink.exe:在输出中获取无效字符

转载 作者:行者123 更新时间:2023-12-02 14:37:42 26 4
gpt4 key购买 nike

我正在使用 plink.exe 在远程服务器上执行命令。我能够与远程服务器连接,但是当我对服务器执行命令时,它将返回无效字符输出,例如:

[?7l[H[2J[?25l[1;1H[37m[40m[2;1H[3;1H[4;1H[5;1H[6;1H[7;1H[8;1H[9;1H[10;1H[11;1H
[12;1H[13;1H[14;1H[15;1H[16;1H[17;1H[18;1H[19;1H[20;1H[21;1H[22;1H[23;1H[24;1H
[?12l[?25h[1;1HMicrosoft Windows [Version 6.1.7601][2;1HCopyright (c) 2009 Microsoft Corporation. All rights reserved.[4;1HC:\Users\Admin>dir /r[5;1H Volume in drive C is UneqSol[6;1H Volume Serial Number is 02F3-A323[8;1H Directory of C:\Users\Admin[10;1H06/17/2014 08:18 PM
.[11;1H06/17/2014 08:18 PM ..[12;1H03/08/2014 11:39 AM .android[13;1H03/08/2014 11:34 AM .AndroidStudioPreview[14;1H06/04/2014 09:39 PM 65 .gplink_config[15;1H03/08/2014 11:26 AM
.gradle[16;1H07/10/2013 07:44 PM
.idlerc[17;1H08/18/2013 03:10 PM 1,189 .opgalaxy7.vr[18;1H03/11/2013 10:59 PM
.swt[19;1H02/22/2014 08:47 PM
.VirtualBox[20;1H07/06/2013 05:52 PM
Contacts[21;1H06/08/2014 02:58 PM
Desktop[22;1H11/23/2013 01:37 PM
Dir[23;1H06/17/2014 09:39 PM
Documents[24;1H06/17/2014 07:01 PM Downloads[24;1H



我与服务器连接的代码是:
 m_Process = new Process();
m_Process.EnableRaisingEvents = true;
m_Process.StartInfo.FileName = "plink.exe";
m_Process.StartInfo.Arguments = "-ssh admin@localhost -pw test";
m_Process.StartInfo.RedirectStandardOutput = true;
m_Process.StartInfo.RedirectStandardInput = true;
m_Process.StartInfo.RedirectStandardError = true;
m_Process.StartInfo.UseShellExecute = false;
m_Process.StartInfo.CreateNoWindow = true;
m_Process.OutputDataReceived += m_Process_OutputDataReceived;

m_Process.Exited += delegate(object sender, EventArgs ev)
{
m_CloseCallback(true);
};

m_Process.Start();
m_Process.BeginOutputReadLine();
m_Process.BeginErrorReadLine();

StreamWriter strw = m_Process.StandardInput;
strw.WriteLine("dir /r"); // send commands

// Wait for application to start and become idle
m_Process.WaitForExit();

而且,如果收到数据,我将获得高于输出的结果,
 private static void m_Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
string value = e.Data;
}

如果任何人都可以找出问题所在,那就太好了。

谢谢

最佳答案

尝试设置输出的编码

m_Process.StartInfo.StandardOutputEncoding = Encoding.ASCII;
m_Process.StartInfo.StandardErrorEncoding = Encoding.ASCII;

这是未经测试的。您可能需要其他编码: http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx

关于c# - plink.exe:在输出中获取无效字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24269346/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com