system$ command and return values & button disable
#1
Hello readers,

[haiku hrev48444 gcc2hy]
[yab 1.72]

i revived an old unfinished project from 2009 at BeGeistert meeting where i tried to start programming with yab with a lot of help from lorglas and lelldorin of besly.de.

[1]
Now i want to play with system$ command (and what it gives back) in my little project.
My application is a GUI for a command line application known as muscled, the base of all BeShare-driven networks.
Main goal for me is to learn how to programm with yab in the right manner, and i'm now on a point where i could need help.
Starting the muscle-daemon is comparable with the top command. Both written in C/C++.
Top gives return values continuously to the user (refreshes all 5 seconds). The muscled also gives feedback as long as it runs.
For now i open a terminal window where the user can follow the server messages [ see attached screenshot ] but i would like to have that messages placed best within my application in a VIEW, because when a user monkeys with that Terminal window and close it, the daemon is stopped and my application does not notice that.
My question: is there a way to "pipe" the output from another cli program into a VIEW. Anyone here who can show me a little code snipped as exaple with the top command?

[2]
Is it possible to set a BUTTON visible but disabled in yab? I want to prevent the user to press the config button while server is running, so i want to disable (but keep visible) that button during server is running [ see attached screenshot ].

[Image: noideahowtoinclude_small.png]

Thanks for your attention!
prOSy
One processor per person is not enough!
JLG
Reply
#2
On the button issue, that is easy

Code:
option set "copyButton", "enabled", 0

That is from the example program TinyTim I posted on this forum, in the Snippets section. When you want to enable it again:

Code:
option set "copyButton", "enabled", 1

Your other issue is trickier. The System$ command runs the parameter once and dumps its output to stdout, which yab can intercept and put into a string variable. The moment you grab that output and paste that onto a view, you'd get a snapshot, but then you lose access to that stream immediately.You want a continuous display, like a log, am I right?

I would redirect the muscled output to a logfile.
Code:
system("muscled > ~/.muscled_log &")
Then once every second or so, use the tail command to grab the last ten lines of that logfile. something like
Code:
a$ = system$("tail ~/.muscled_log")
Paste that onto the view, leave it for a second, wipe the view and repeat. It will flicker badly and if you get more than ten lines of output in a second you will lose information. But you can always have a function on the menu to display the entire logfile.

This is all off the top of my head, BTW. I am very far away from a yab installation right now. Debug, debug, debug!

Anybody else? If there is a way to pipe a Unix stream directly into, say, a listbox, I'm all ears.

Another approach would be to use the hey command to remove the tab from your Terminal window. That makes it a bit harder for the user to close it down. Also harder to move it around, so also use hey to position it somewhere in a corner and resize it.
Reply
#3
(09-10-2015, 02:56 AM)clasqm Wrote: On the button issue, that is easy

Code:
option set "copyButton", "enabled", 0
...
Thanks a lot. Already done, works perfect!

Quote:Your other issue is trickier. ... You want a continuous display, like a log, am I right?
Yes, indeed. that would be the N°1 solution, if possible.

Quote:I would redirect the muscled output to a logfile.
...
Paste that onto the view, leave it for a second, wipe the view and repeat. It will flicker badly and if you get more than ten lines of output in a second you will lose information. But you can always have a function on the menu to display the entire logfile.
Good hint, which led me to another possibility. I could wirte log-messages always to a logfile and if user needs to look at that log, a button with system(tail -f ~/.logfile.log) or so opens a Terminal window and enables a look to the file.
And if that window should be inadvertently closed it would not harm my application.

Quote:Anybody else? If there is a way to pipe a Unix stream directly into, say, a listbox, I'm all ears.
I'm all ears too! (-:

Quote:Another approach would be to use the hey command to remove the tab from your Terminal window. That makes it a bit harder for the user to close it down. Also harder to move it around, so also use hey to position it somewhere in a corner and resize it.
A nice possibility too. From what i've seen i have to dig into that hey stuff.

It seems i have a little bit longer to think about it and to test various solutions.
Anyway, thanks again, clasqm!

prOSy
One processor per person is not enough!
JLG
Reply
#4
at prOSy:

Code:
Programname$="Example top command output in yab"
Developer$="Lelldorin"

screenWidth = peek("desktopwidth")
screenHeight = peek("desktopheight")

ProgramFolder$="/boot/home/Desktop/for_prOSy"

WINDOW OPEN screenWidth/2-400,screenHeight/2-300 TO screenWidth/2+400,screenHeight/2+300, "TopCommandOutput", "Example top command output in yab"
    TEXTEDIT 5,5 TO 795,565, "TE:Output", 1, "TopCommandOutput"
    
    DRAW TEXT 5,585, "counter to reload (40):0", "TopCommandOutput"
looprun=30

//Main Loop    
dim part$(1)

inloop = true

while(inloop)
    looprun=looprun+1
    DRAW FLUSH "TopCommandOutput"
    DRAW TEXT 5,585, "counter to reload (40):"+str$(looprun), "TopCommandOutput"
    //print looprun
    msg$ = message$
    //print looprun
    
    
    if (split(msg$, part$(), ":|") > 2) then
        PartOne$=part$(1)
        PartTwo$=part$(2)
        PartThree$=part$(3)
    fi

    if (split(msg$, part$(), ":|") > 3) then
        PartFour$ = part$(4)
    fi

    if (msg$ <> "") print msg$
    

    switch msg$
    
    case PartOne$+":_QuitRequested|"
        WINDOW CLOSE PartOne$
        break
        
        

        
    
    default:

    end switch
    
    if(looprun=40)then
        //print "here"
        //i=0
        if(IfExists("/boot/home/config/settings/top_output")) then
            output$=system$("rm -r /boot/home/config/settings/top_output_temp")
        else
        endif
        output$=system$("top > /boot/home/config/settings/top_output_temp&kill top")
        wait 2
        output$=system$("cp /boot/home/config/settings/top_output_temp /boot/home/config/settings/top_output")
    elseif(looprun>40)then
        TEXTEDIT CLEAR "TE:Output"
        //print "loop ab:" +str$(looprun)
        //wait 2
        readout=open("/boot/home/config/settings/top_output", "r")
        while (not EOF(readout))
            x=x+1
            print "x:"+str$(x)
            dim ReadTopCommandOutput$(x)
                line input #readout b$
                ReadTopCommandOutput$(x)=b$    
                for i = 1 to readout
                    //print "i:"+str$(i)
                    TEXTEDIT ADD "TE:Output", ReadTopCommandOutput$(i)+"\n"                    
                next i
        wend
        i=0
        x=0
        looprun=0
    else
        
    endif

    if(window count<1) inloop = false

    sleep 0.1
    

wend

sub IfExists(filename$)
     return not system("test -e "+filename$)
end sub
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)
Free Web Hosting