问题描述
public class ProcessHandler
{
private static Process process;
private static ListenerHandler listenerHandler = new ListenerHandler();
public static void Start(string fileName,string arguments)
{
process = new Process();
process.StartInfo.FileName = fileName;
if (arguments != "")
process.StartInfo.Arguments = arguments;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNowindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
process.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler);
process.Start();
process.BeginoutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
}
private static void OutputHandler(object sender,DataReceivedEventArgs e)
{
if (e.Data != null)
Console.WriteLine(e.Data);
}
private static void Process_OutputDataReceived(object sender,DataReceivedEventArgs e)
{
// Todo.
}
public static void Kill()
{
try
{
if (!process.HasExited)
process.Kill();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,ex.GetType().ToString());
}
}
}
并且想用它来启动appium
服务器。
在我的 machine
中,我想要启动 appium
服务器,我只需打开 cmd
窗口,输入 appium
并启动服务器。
所以我尝试在这个类的例子中这样使用它:
ProcessHandler.Start("appium","");
并收到此错误(在 process.Start() 处):
System.ComponentModel.Win32Exception: '系统找不到文件 指定'
ProcessHandler.Start("notepad",@"C:\log.txt");
这很好用。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)