-
October 2nd, 2017, 07:16 AM
#1
Using plink to get information from a Linux Box for the first time
Good morning,
I am trying to send a command from a Windows 10 PC to a Linux device to get information for the first time.
I can do this in and command window as follows:
echo n | plink.exe -ssh -pw root root@172.31.255.1:22 ifconfig
My question is how do I do this in C#? I have tried the following code but do not know how to get the "echo n | " portion into it:
Code:
using System;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
string output = string.Empty;
string error = string.Empty;
public Form1()
{
InitializeComponent();
}
private void TEST_Click(object sender, EventArgs e)
{
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = @"C:\Program Files (x86)\PuTTY\plink.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.Start();
System.IO.StreamWriter myStreamWriter = myProcess.StandardInput;
String inputText = " -ssh -pw root root@172.31.255.1:22 ifconfig";
myStreamWriter.WriteLine(inputText);
string output = myProcess.StandardOutput.ReadToEnd();
string error = myProcess.StandardError.ReadToEnd();
}
}
}
Following is a picture of my situation. Any help would be appreciated.
Thanks - L. Madeux....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|