1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| public partial class Form1 : Form
{
private String output;
private Boolean boo;
public Form1()
{
InitializeComponent();
boo = false;
}
private void Form1_Load(object sender, EventArgs e)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "perl.exe";
proc.StartInfo.Arguments = "test.pl";//"install Crypt-SSLeay/Crypt-SSLeay-0.51.ppd";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler);
proc.ErrorDataReceived += new DataReceivedEventHandler(SortOutputHandler);
proc.Start();
proc.BeginErrorReadLine();
proc.BeginOutputReadLine();
StreamWriter writer = proc.StandardInput;
writer.AutoFlush = true;
int i = 0;
while (!proc.HasExited)
{
if (boo)
{
writer.WriteLine(output);
boo = false;
}
}
writer.Close();
proc.CancelErrorRead();
proc.CancelOutputRead();
proc.Close();
// Application.Exit();
}
private void SortOutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
boo = true;
output = outLine.Data;
if (!String.IsNullOrEmpty(outLine.Data))
{
if (outLine.Data[outLine.Data.Length - 1] == '?')
{
output = "coin.txt";
}
else if (outLine.Data.IndexOf("[yes]") != -1)
{
output = "yes";
}
else if (outLine.Data.IndexOf("[no]") != -1)
{
output = "no";
}
}
}
} |
Partager