diff --git a/Example/UsingTest/Script/EGSaveTest.cs b/Example/UsingTest/Script/EGSaveTest.cs index 71d5ade..07965c1 100644 --- a/Example/UsingTest/Script/EGSaveTest.cs +++ b/Example/UsingTest/Script/EGSaveTest.cs @@ -20,15 +20,21 @@ namespace EGFramework.Examples.Test{ // this.EGEnabledProtocolTool(); // this.EGEnabledProtocolTool(); // this.EGEnabledProtocolTool(); - // this.EGOnMessage(); - // // this.EGRegisterMessageEvent((e,sender)=>{ - - // // }); + this.EGOnMessage(); + this.EGRegisterMessageEvent((e,sender)=>{ + }); + TestProcess(); // //TestSsh(); // //TestTCPSend(); // TestTCPServer(); - TestFTP(); + // TestFTP(); + } + + public override void _ExitTree() + { + this.EGProcess().CloseProcess("cmd.exe"); } + public void TestFTP(){ EGFtpSave ftp = new EGFtpSave(); ftp.InitSave("127.0.0.1"); @@ -38,6 +44,12 @@ namespace EGFramework.Examples.Test{ } } + public void TestProcess(){ + this.EGEnabledProtocolTool(); + this.EGProcess().InitProcess("cmd.exe"); + this.EGProcess().SendStringData("cmd.exe","ipconfig"); + } + public async void TestSsh(){ await this.EGSsh().ConnectSsh("127.0.0.1","jkpete",new PrivateKeyFile("../../../.ssh/id_ed25519")); this.EGSendMessage(new EasyMessage(){sendString = "ls -la"},"127.0.0.1",ProtocolType.SSHClient); diff --git a/addons/EGFramework/Module/ProtocolTools/EGProcess.cs b/addons/EGFramework/Module/ProtocolTools/EGProcess.cs index 5a6302a..5ef86f9 100644 --- a/addons/EGFramework/Module/ProtocolTools/EGProcess.cs +++ b/addons/EGFramework/Module/ProtocolTools/EGProcess.cs @@ -37,8 +37,13 @@ namespace EGFramework{ try{ if(!Processes.ContainsKey(processName)){ Process process = new Process(); - process.StartInfo.FileName = processName.GetStrFrontSymbol(' '); - process.StartInfo.Arguments = processName.GetStrBehindSymbol(' ');; // Add any arguments if needed + if(processName.GetStrFrontSymbol(' ') == ""){ + process.StartInfo.FileName = processName.GetStrBehindSymbol(' '); + }else{ + process.StartInfo.FileName = processName.GetStrFrontSymbol(' '); + process.StartInfo.Arguments = processName.GetStrBehindSymbol(' ');; // Add any arguments if needed + } + EG.Print("[open process]"+process.StartInfo.FileName+" "+process.StartInfo.Arguments); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; @@ -48,6 +53,7 @@ namespace EGFramework{ process.OutputDataReceived += (sender, e) => { if (!string.IsNullOrEmpty(e.Data)) { ResponseMsgs.Enqueue(new ResponseMsg { sender = processName, stringData = e.Data }); + EG.Print("[process output]"+processName+" "+e.Data); } }; process.Exited += (sender, e) => { @@ -58,7 +64,16 @@ namespace EGFramework{ } } catch(Exception e){ - ErrorLogs = "[open port error]" + e.ToString(); + ErrorLogs = "[open process error]" + e.ToString(); + EG.Print(ErrorLogs); + } + } + + public void CloseProcess(string processName){ + if(Processes.ContainsKey(processName)){ + Processes[processName].Kill(); + Processes.Remove(processName); + EG.Print("[close process]"+processName); } } @@ -88,4 +103,13 @@ namespace EGFramework{ return EGArchitectureImplement.Interface; } } + public static class CanGetEGProcessExtension{ + public static EGProcess EGProcess(this IEGFramework self){ + return self.GetModule(); + } + + public static Process EGGetSshClient(this IEGFramework self,string processName){ + return self.GetModule().Processes[processName]; + } + } } \ No newline at end of file