Ooops
October 24, 2021, 09:19:18

Author Topic: Making External Console Reporter for a loading Editor  (Read 664 times)

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 745
  • Nothing is personal
Making External Console Reporter for a loading Editor
« on: September 26, 2021, 08:36:34 »
Hi. I want to make a loading console for my Editor.
What i mean is an external Window that reports the loading process while the editor is loaded..

The way i made it so far is by making an external GUI exe Window that get its info by reading a Text File whenever it changes by the editor sending reports.

so it needs to check the file size to decide if the file has changed..

Is their a better way to do this ? or my way is ok?

I think im gonna use Createprocess command to run the console
but in the case that my editor crashes, i need to find a way that the console will shut down too.
so i need a way to check if my editor is running or not. but thats less important
Some things can break me down.
Some cant

Offline col

  • Hero Member
  • *****
  • Posts: 600
Re: Making External Console Reporter for a loading Editor
« Reply #1 on: September 26, 2021, 11:19:59 »
Hiya,

Hmm, I only know of a Windows only way to achieve exactly this. I'd guess that other OSs would have something similar.

This example is from MS to give an example of to use the Api

https://docs.microsoft.com/en-us/windows/win32/fileio/obtaining-directory-change-notifications

If you need any help getting it working with BMax let me know.

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 745
  • Nothing is personal
Re: Making External Console Reporter for a loading Editor
« Reply #2 on: September 26, 2021, 11:32:17 »
its not such a complex task..
i already made it in my way and ill share it later..
just wondering whats the best way..

i could also comunicate using UDP or something.
but ill communicate with text file
Some things can break me down.
Some cant

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 745
  • Nothing is personal
Re: Making External Console Reporter for a loading Editor
« Reply #3 on: September 26, 2021, 12:20:23 »
OK. it does not work for some reason..
the external windows is not updated.. like it waits for the editor to upload..

Is their a way to open CMD window and send text messages to this win?
Some things can break me down.
Some cant

Offline col

  • Hero Member
  • *****
  • Posts: 600
Re: Making External Console Reporter for a loading Editor
« Reply #4 on: September 26, 2021, 12:48:37 »
If you want some kind of inter process communication? Then using TProcess will allow 2 'apps' to talk to each other via its pipe read and write methods.

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 745
  • Nothing is personal
Re: Making External Console Reporter for a loading Editor
« Reply #5 on: September 26, 2021, 12:59:28 »
Ok Ill Try The Read and Write Pipe Method
Some things can break me down.
Some cant

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 745
  • Nothing is personal
Re: Making External Console Reporter for a loading Editor
« Reply #6 on: September 26, 2021, 13:31:05 »
How do I read process from the target process?

writing to process is simple..

but i need to get the process address from the process . how do i do that?
Some things can break me down.
Some cant

Offline col

  • Hero Member
  • *****
  • Posts: 600
Re: Making External Console Reporter for a loading Editor
« Reply #7 on: September 26, 2021, 13:58:41 »
You could pass it as a command line startup parameter?

Offline col

  • Hero Member
  • *****
  • Posts: 600
Re: Making External Console Reporter for a loading Editor
« Reply #8 on: September 26, 2021, 15:42:21 »
Oh I misunderstood what you mean. I'm assuming both apps are written in BMax? In the 'main' app you start up the 'child' app using TProcess, and TProcess handles the connections. In your child app you can read/write to/from stdin/stdout, and the main app will use TProcess pipe to read/write.

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 745
  • Nothing is personal
Re: Making External Console Reporter for a loading Editor
« Reply #9 on: September 26, 2021, 18:15:50 »
I will glad to an example cause i have no idea how to use i.
meanwhile im searching.

anyway im trying to make a console and so far it does no transmit data while loading so..ill keep trying
« Last Edit: September 26, 2021, 19:17:57 by Hardcoal »
Some things can break me down.
Some cant

Offline Henri

  • Sr. Member
  • ****
  • Posts: 355
Re: Making External Console Reporter for a loading Editor
« Reply #10 on: September 27, 2021, 21:07:28 »
Hi,

here is a basic example of communicating via process pipe using standardio (every application has their own).

Compile the tool.bmx in release mode or rename the file variable to tool.debug.exe . After that run the main app.

'Main app
Code: BlitzMax
  1. '-------------------
  2. 'StandardIO example
  3. '-------------------
  4.  
  5. Local proc:TProcess = CreateProcess("tool.exe")
  6. If Not proc Then Print("Could not create tool app process"); End
  7.  
  8. Local feed:String, count:Int
  9.  
  10. Print "~nCount to 5:~n"
  11.  
  12. If ProcessStatus(proc)
  13.        
  14.         Delay 100
  15.        
  16.         proc.pipe.WriteString("Main_app: Sending ~qHello~q~n")
  17.        
  18.         Repeat
  19.                 If proc.pipe.ReadAvail() Then
  20.                         feed:+ proc.pipe.ReadString(proc.pipe.ReadAvail())
  21.                 EndIf
  22.                
  23.                 Delay 1000;
  24.                 If count > 4 Then Exit
  25.                 count:+ 1
  26.                
  27.                 Print "Counting " + count + ".."
  28.         Forever
  29.        
  30.         proc.pipe.Close()
  31.        
  32. Else
  33.         Print("tool.exe not running. Exiting.."); End
  34. EndIf
  35.  
  36. Delay 1000
  37.  
  38. Print "~n" + feed
  39. Print "Ending process.."
  40.  
  41. TerminateProcess(proc)
  42.  
  43. End
  44.  


'Tool app
Code: BlitzMax
  1. '--------
  2. 'tool.bmx
  3. '--------
  4.  
  5. Local s:String
  6.  
  7. While True
  8.        
  9.         'Waiting for newline character
  10.         s = ReadStdin()
  11.        
  12.         'Respond
  13.         WriteStdout(s + "~nTool_app: Responding with ~qHello back!~q")
  14. Wend
  15.  


-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline Derron

  • Hero Member
  • *****
  • Posts: 3668
Re: Making External Console Reporter for a loading Editor
« Reply #11 on: September 28, 2021, 08:27:29 »
Of course you should do it a bit more "complicated" at the end.
Means having a type which handles all the communication for you (lurking around scanning for new input, handling queued up outgoing messages ...).

Also messages should have "IDs" so you know which came in what order (sequential messages).



@ Henri
I think it could be an interesting piece of code to attach to an running process (debuggers seem to be capable under circumstances). Am not sure if that is even doable "security wise" as it would mean to be able to "listen" to an else "separate" running program.


Aside of that a "process communication" module might be interesting too ... so something providing the basement of a crossplatform solution to send and receive stdio-based messaqes amongst parent ant child processes.


bye
Ron

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal