1.c#调用非c#编写的EXE:Process
引用空间: System.Diagnostics;
process.StartInfo.FileName="lame.exe"; //设置要启动的应用程序
process.StartInfo.Arguments=" -h --abr 128 test.wav testOut.mp3 ";//设置启动应用程序时的命令行参数
2.正则表达式匹配lame.exe输出的信息
引用空间:System.Text.RegularExpressions;
@"(/d+)/(/d+)/D+(/d+)/D+([/d:]+)/D+([/d:]+)/D+([/d:]+)/D+([/d:]+)/D+([/d/.]+)/D+([/d:]+)"
3.事件、委托、线程
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Diagnostics ;
- using System.Threading ;
- using System.Windows.Forms;
- namespace CSharpShell
- {
- public delegate void eventDone();
- public delegate void eventProgress(LameProgress Progress);
- public delegate void eventIgnoredLine(string Line);
- public delegate void eventCanceled();
- public class Shell
- {
- private Process _lameProcess = new Process();
- private Thread _lameThread;
- private int _percentDone;
- private bool _isRunning = false;
- private ProcessStartInfo _startInfo = new ProcessStartInfo();
- private Regex _regLine=new Regex (@"(/d+)/(/d+)/D+(/d+)/D+([/d:]+)/D+([/d:]+)/D+([/d:]+)/D+([/d:]+)/D+([/d/.]+)/D+([/d:]+)", RegexOptions.IgnoreCase
- | RegexOptions.CultureInvariant
- | RegexOptions.IgnorePatternWhitespace
- | RegexOptions.Compiled );
- private string _inFile;
- private string _outFile;
- private string _options;
- public event eventDone Done;
- public event eventProgress Progress;
- public event eventIgnoredLine IgnoredLine;
- public event eventCanceled Canceled;
- public Shell()
- {
- DefStartInfo();
- _startInfo.WorkingDirectory = Application.StartupPath;
- }
- public Shell(string InFile, string OutFile, string LamePath, string Options)
- {
- DefStartInfo();
- if (string.IsNullOrEmpty(LamePath))
- _startIn