Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Retrieve text from the hidden command-line window
#1
https://www.quickmacros.com/forum/showth...6#pid36746

I want to add the following features using the code from the link above (on Line11 before):

`frpc.exe` comes from an open-source project(https://github.com/fatedier/frp/releases/tag/v0.59.0).
Issue 1: Unable to execute the command-line program `frpc.exe`, the following error occurs as shown in the image below.
https://i.ibb.co/3kmg08n/A.jpg
I can manually start `frpc.exe` using the following command-line code.
start frpc.exe -c frpc.toml

Additionally, the three features I need are described in detail in the comments within the code below.

I'm not sure if these features can be implemented, thank you in advance.
Code:
Copy      Help
process.terminate("frpc.exe");
string frpc = folders.ThisApp + @"\frpc.exe"; print.it(frpc);
string cl = "-c frpc.toml";

//Issue1: Unable to execute the command-line program frpc.exe
run.it(frpc, cl, dirEtc: new() { CurrentDirectory = folders.ThisApp /*, WindowState = ProcessWindowStyle.Hidden*/ }); //In actual use: the window is hidden.

//Todo1:
//Retrieve the text from the hidden `frpc` command-line window, save it to the variable `s`, and print it.
//string s = getFrpcLogText(); print.it(s);

//Todo2:
//Continuously monitor the text in the hidden frpc command-line window.
//When the specified text (e.g., "start proxy success") appears, a dialog box should pop up displaying the message: "Connection successful!"


600.s(); //In actual use: here is HTTP server code Line 11 ....(https://www.libreautomate.com/forum/showthread.php?tid=7468&pid=36746#pid36746)

//Todo3:
//Ensure that the frpc.exe program always terminates when the "End Task" option is clicked from the context menu of the program's taskbar icon (or when the program encounters an unexpected error).
//process.terminate("frpc.exe");

#2
Did you try run.console. Or class consoleProcess if need input.
#3
The following code executes normally, but the text in the hidden command-line window only appears after the program ends.
 
Code:
Copy      Help
process.terminate("frpc.exe");
string frpc = folders.ThisApp + @"\frpc.exe"; print.it(frpc);
string cl = "-c frpc.toml";

run.console(out var text, frpc, cl, curDir:$"{folders.ThisApp}", encoding: Console.OutputEncoding); print.it(text);

Quote:class consoleProcess if need input.

How to use `consoleProcess`?"  I've looked up some information, but I'm finding it a bit difficult.

I didn't find any content related to `consoleProcess` in the cookbook.
However, I found some help about `consoleProcess` in the link below. Where can I download the program(exe\console1\console1.exe, Is the source code available?) used in the examples?

Class consoleProcess | LibreAutomate
#4
Quote:but the text in the hidden command-line window only appears after the program ends
Example in cookbook article "Run console program and get its output text" .
 


A test program can be easily created in LA. For input use Console.ReadLine.
#5
thank you! LA is so powerful!

Using the code below, I was able to solve most of my needs, and the value of the variable `s` is updated in real time.
However, how can I implement the functionality for Todo2?

I asked ChatGPT, but didn't get the correct answer, possibly because I don't understand the implementation principles.
 
Code:
Copy      Help
run.thread(() => run.console(s => print.it(s), frpc, cl, encoding: Encoding.UTF8));
//Todo2:
//Continuously monitor the text in the hidden frpc command-line window.
//When the specified text (e.g., "start proxy success") appears, a dialog box should pop up displaying the message: "Connection successful!"
//When the specified text (e.g., "unreachable network") appears, a dialog box should pop up displaying the message: "unreachable"

// HTTP server Code
#6
It's the second code example in cookbook article "Run console program and get its output text". Your callback function receives a line and can do with it whatever.
#7
I don't have a deep understanding of callback functions, so implementing them is a bit difficult for me.
#8
I'll add another example in the article.
 
Code:
Copy      Help
/// Let my callback function receive output text lines in real time.

run.console(s => print.it(s), @"C:\Test\console2.exe"); //print it

run.console(s => { if (s.Starts("Error")) throw new Exception(s); }, @"C:\Test\console2.exe"); //or do whatever with it
#9
Thanks again for your help.  
It seems I’ve found the answer.


Forum Jump:


Users browsing this thread: 3 Guest(s)