Browse Source

add process test

master
jkpete 3 months ago
parent
commit
335067eebd
  1. 22
      Example/UsingTest/Script/EGSaveTest.cs
  2. 30
      addons/EGFramework/Module/ProtocolTools/EGProcess.cs

22
Example/UsingTest/Script/EGSaveTest.cs

@ -20,15 +20,21 @@ namespace EGFramework.Examples.Test{ @@ -20,15 +20,21 @@ namespace EGFramework.Examples.Test{
// this.EGEnabledProtocolTool<EGSsh>();
// this.EGEnabledProtocolTool<EGTCPClient>();
// this.EGEnabledProtocolTool<EGTCPServer>();
// this.EGOnMessage<EasyMessage>();
// // this.EGRegisterMessageEvent<EasyMessage>((e,sender)=>{
// // });
this.EGOnMessage<EasyMessage>();
this.EGRegisterMessageEvent<EasyMessage>((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{ @@ -38,6 +44,12 @@ namespace EGFramework.Examples.Test{
}
}
public void TestProcess(){
this.EGEnabledProtocolTool<EGProcess>();
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);

30
addons/EGFramework/Module/ProtocolTools/EGProcess.cs

@ -37,8 +37,13 @@ namespace EGFramework{ @@ -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{ @@ -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{ @@ -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{ @@ -88,4 +103,13 @@ namespace EGFramework{
return EGArchitectureImplement.Interface;
}
}
public static class CanGetEGProcessExtension{
public static EGProcess EGProcess(this IEGFramework self){
return self.GetModule<EGProcess>();
}
public static Process EGGetSshClient(this IEGFramework self,string processName){
return self.GetModule<EGProcess>().Processes[processName];
}
}
}
Loading…
Cancel
Save