Page 1 of 1

capture cli output

Posted: Fri Mar 31, 2017 2:05 pm
by emeck
Hello,

I want to run a cli program from a Hollywood app, and to capture any output from the ran cli program. What I'm doing now is use a temporary file in T:, like this this:

Code: Select all

Local today$

Execute("date > T:today")

todayfile=OpenFile(Nil, "T:today")
today$=ReadLine(todayfile)
CloseFile(todayfile)
DeleteFile("T:today")

moai.Set("second", "text", today$)  ;send the output to the status bar
Ithis the best way or can I capture cli output without the temporary file?

Re: capture cli output

Posted: Sat Apr 01, 2017 3:47 pm
by airsoftsoftwair
No, I think what you're doing is the best way to capture CLI output with Hollywood.

Re: capture cli output

Posted: Mon Apr 10, 2017 9:40 am
by lazi
There is a way to avoid temp files.
However it has a problem if the executed command does not send anything to the named pipe:

Code: Select all

Execute("date >pipe:day")

todayfile=OpenFile(Nil, "pipe:day")
pos,today$=-1,""
While FilePos(todayfile)<>pos
	pos=FilePos(todayfile)
	today$=today$..ReadLine(todayfile)
Wend
CloseFile(todayfile)

NPrint(today$)
WaitLeftMouse           

Re: capture cli output

Posted: Thu Jan 03, 2019 3:57 pm
by jPV
airsoftsoftwair wrote:
Sat Apr 01, 2017 3:47 pm
No, I think what you're doing is the best way to capture CLI output with Hollywood.
Would it be possible to implement an event handler that would get triggered always when a program started with the Run() command would output something? RunOutput or such... it would be handy when creating GUIs for shell programs.

Re: capture cli output

Posted: Sat Jan 05, 2019 10:27 pm
by airsoftsoftwair
Hmm, maybe ;)

Re: capture cli output

Posted: Sat Jun 08, 2019 9:00 pm
by airsoftsoftwair
Unfortunately, this is technically not possible because it would have to be implemented through pipes but when redirecting a program's output to a pipe, the internal buffering routines won't flush on a line break but only when a certain platform-dependent buffer threshold is exceeded (e.g. 4096 bytes). This makes it impossible to capture the output of console programs in realtime. It's a little sad because that certainly would have been a nice feature but AFAICS there's no way to implement it, except maybe on Linux by using pseudoterminals.

Re: capture cli output

Posted: Wed Jun 12, 2019 4:44 pm
by airsoftsoftwair
Reflecting on it further, I now think that even though stdio buffering might prohibit real-time output capturing, it's still a good idea to have such a feature because most programs will just continually output text to stdout and this of course can be easily captured. There'll only be problems in case an external program pauses outputting text at some point for whatever reason. In that case, not all output might make its way to Hollywood instantly because of stdio buffering. But it will reach Hollywood as soon as the program continues output to stdout. But since most programs don't behave that way, it's probably not much of an issue, so the feature is now implemented:

Code: Select all

- New: Added "RunOutput" event handler; this can be used to capture the output of programs started using
  Run(); note that output will normally not be delivered in real-time because of stdio buffering but
  if the external program continually outputs text it will arrive pretty instantly at your "RunOutput"
  callback; note that due to OS limitations, this is currently unsupported on AmigaOS 3.x; MorphOS
  users require at least MorphOS 3.12
Note that it's not possible to support it on OS 3.x because the queue handler on OS 3.x is pretty much broken. But all the other Amigaoids will work (MorphOS requires 3.12, though).

Re: capture cli output

Posted: Wed Jun 12, 2019 6:05 pm
by jPV
Great work \o/

Re: capture cli output

Posted: Fri Jun 14, 2019 9:12 am
by emeck
Thank you!