capture cli output

Find quick help here to get you started with Hollywood
Post Reply
User avatar
emeck
Posts: 66
Joined: Fri Apr 03, 2015 3:17 pm

capture cli output

Post by emeck » Fri Mar 31, 2017 2:05 pm

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?

User avatar
airsoftsoftwair
Posts: 3072
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: capture cli output

Post by airsoftsoftwair » Sat Apr 01, 2017 3:47 pm

No, I think what you're doing is the best way to capture CLI output with Hollywood.

User avatar
lazi
Posts: 333
Joined: Thu Feb 24, 2011 11:08 pm

Re: capture cli output

Post by lazi » Mon Apr 10, 2017 9:40 am

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           

User avatar
jPV
Posts: 261
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: capture cli output

Post by jPV » Thu Jan 03, 2019 3:57 pm

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.

User avatar
airsoftsoftwair
Posts: 3072
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: capture cli output

Post by airsoftsoftwair » Sat Jan 05, 2019 10:27 pm

Hmm, maybe ;)

User avatar
airsoftsoftwair
Posts: 3072
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: capture cli output

Post by airsoftsoftwair » Sat Jun 08, 2019 9:00 pm

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.

User avatar
airsoftsoftwair
Posts: 3072
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: capture cli output

Post by airsoftsoftwair » Wed Jun 12, 2019 4:44 pm

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).

User avatar
jPV
Posts: 261
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: capture cli output

Post by jPV » Wed Jun 12, 2019 6:05 pm

Great work \o/

User avatar
emeck
Posts: 66
Joined: Fri Apr 03, 2015 3:17 pm

Re: capture cli output

Post by emeck » Fri Jun 14, 2019 9:12 am

Thank you!

Post Reply