Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
callback function receive output text lines in real time
#1
I am very eager to know how to implement a function in QM similar to the one below in LA. Thank you!
https://www.quickmacros.com/forum/showth...9#pid38099
 
Code:
Copy      Help
//LA code:
run.console(s => { if (s.Starts("Error")) throw new Exception(s); }, @"C:\Test\console2.exe"); //or do whatever with it
#2
How can I quickly find the source code definition of the above LA function? I want to implement it using generic C# code and then use it in QM.

I tried the following QM code, but in actual use, the background program is a console application, and I need to continuously monitor the output text of the console program.

Macro Macro37
Code:
Copy      Help
run "notepad.exe"
mac "sub.paint"

#sub paint
run "mspaint.exe" "" "" "" 2
rep
,0.5
,if sub.getProcN("notepad.exe")=0
,,ShutDownProcess "mspaint"
,,break

#sub getProcN
function str'proName
ARRAY(str) a; EnumProcessesEx 0 a 1
int n=0; str p=proName

for _i 0 a.len
,if a[_i].end(p)
,,n+1
ret n
#3
Find function source: click it, press F12 (command "Go to definition"), OK.
#4
Thanks for your help. I had tried using F12 before, and I just realized that I need to log in to GitHub to view the code definitions.  

I tried using ChatGPT to solve the issue, but it seems to require more context for a proper solution.  

I feel like I might have overcomplicated the problem.  

The following LA code works well; is there no alternative function in QM?  
 
Code:
Copy      Help
process.terminate("ssh.exe");

string ssh ="ssh.exe"; string cl = "-R 80:localhost:4455 serveo.net";

run.thread(() => run.console(s => { if (s.EndsWith(".serveo.net")) print.it("serveo.net is OK"); }, ssh, cl, encoding: Encoding.UTF8));

30.s();
#5
QM does not have such function.
#6
Quote:QM does not have such function.

I seem to have found a built-in function called `RunConsoleCallback` that might solve my problem

https://www.quickmacros.com/forum/showth...0#pid27790

I tried the following code, and it seems to produce the desired result. Are there any areas in the code that need optimization? Thank you!
discovered one issue: After the main process ends, the ssh.exe process does not close.

Macro Macro38
Code:
Copy      Help
out

mac "sub.sshExc"

wait 10

#sub sshExc
ShutDownProcess "ssh"

int ec=RunConsoleCallback(&sub.OnConsoleOutput 0 "ssh -R 80:localhost:4455 serveo.net" "" 0x4801) 
out ec

#sub OnConsoleOutput
function# cbParam $s
out F"<{s}>"
#7
In the code above, when I set the SSH console program window to be displayed, no text is shown in the window, but there is output in the QM output panel.
Is there any way to terminate the SSH process when the main program closes?

https://i.ibb.co/4Fvzd0c/A.gif

I tried adding the following code. The `EndThread` function doesn't work, and the `ShutDownProcess` function works when the main program runs normally, but it doesn't work when the main thread exits unexpectedly.

Code:
Copy      Help
if(IsThreadRunning("Macro38:sshExc"))
,out "FunctionX is running"
,EndThread "Macro38:sshExc" ;;NO
,ShutDownProcess "ssh" ;;OK
#8
Using the code below, the SSH process will terminate when an error occurs.  
However, when I manually end the main process from the Task Manager, the SSH process still remains. It seems I can only resolve this by modifying the function in the link below.
https://www.quickmacros.com/forum/showth...0#pid27790

Code:
Copy      Help
err+
,ShutDownProcess "ssh"


Forum Jump:


Users browsing this thread: 3 Guest(s)