Posts: 1,049
Threads: 249
Joined: Jul 2022
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
//LA code:
run.console(s => { if (s.Starts("Error")) throw new Exception(s); }, @"C:\Test\console2.exe"); //or do whatever with it
Posts: 1,049
Threads: 249
Joined: Jul 2022
09-27-2024, 05:48 AM
(This post was last modified: 09-27-2024, 05:51 AM by Davider.)
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
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
Posts: 12,095
Threads: 142
Joined: Dec 2002
Find function source: click it, press F12 (command "Go to definition"), OK.
Posts: 1,049
Threads: 249
Joined: Jul 2022
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?
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();
Posts: 12,095
Threads: 142
Joined: Dec 2002
QM does not have such function.
Posts: 1,049
Threads: 249
Joined: Jul 2022
09-28-2024, 02:15 AM
(This post was last modified: 09-28-2024, 10:27 AM by Davider.)
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
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}>"
Posts: 1,049
Threads: 249
Joined: Jul 2022
09-28-2024, 10:31 AM
(This post was last modified: 09-28-2024, 11:24 AM by Davider.)
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.
if(IsThreadRunning("Macro38:sshExc"))
,out "FunctionX is running"
,EndThread "Macro38:sshExc" ;;NO
,ShutDownProcess "ssh" ;;OK
Posts: 1,049
Threads: 249
Joined: Jul 2022
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
err+
,ShutDownProcess "ssh"