rajesh kumar

rajesh kumar

  • NA
  • 408
  • 14.4k

Cannot Convert string to char

Nov 20 2017 6:11 PM
Hi everybody, i have created a winform application which run Command Prompt Commands but the problems is  i am getting an error Like "Cannot Convert string to char" in this line " psi = new ProcessStartInfo(TextBox1.Text.Split(" ")(0), TextBox1.Text.Split(" ")(1)); "  Can anybody please help me
 
 
 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
public partial class Form1:Form
{
private ProcessStartInfo psi;
private Process cmd;
private delegate void InvokeWithString(string text);
private void Button1_Click(System.Object sender, System.EventArgs e)
{
try {
cmd.Kill();
} catch (Exception ex) {
}
TextBox2.Clear();
if (TextBox1.Text.Contains(" ")) {
psi = new ProcessStartInfo(TextBox1.Text.Split(" ")(0), TextBox1.Text.Split(" ")(1));
} else {
psi = new ProcessStartInfo(TextBox1.Text);
}
System.Text.Encoding systemencoding = default(System.Text.Encoding);
System.Text.Encoding.GetEncoding(Globalization.CultureInfo.CurrentUICulture.TextInfo.OEMCodePage);
var _with1 = psi;
_with1.UseShellExecute = false;
_with1.RedirectStandardError = true;
_with1.RedirectStandardOutput = true;
_with1.RedirectStandardInput = true;
_with1.CreateNoWindow = true;
_with1.StandardOutputEncoding = systemencoding;
_with1.StandardErrorEncoding = systemencoding;
cmd = new Process {
StartInfo = psi,
EnableRaisingEvents = true
};
cmd.ErrorDataReceived += Async_Data_Received;
cmd.OutputDataReceived += Async_Data_Received;
cmd.Start();
cmd.BeginOutputReadLine();
cmd.BeginErrorReadLine();
}
private void Async_Data_Received(object sender, DataReceivedEventArgs e)
{
this.Invoke(new InvokeWithString(Sync_Output), e.Data);
}
private void Sync_Output(string text)
{
TextBox2.AppendText(text + Environment.NewLine);
TextBox2.ScrollToCaret();
}
}

Answers (4)