Page 1 of 1

Output command result to PB EditorGadget??

Posted: Tue Feb 20, 2007 1:44 pm
by merihevonen
Hello!

I'm developing a small program for a project and the GUI needs to have an EditorGadget where the output of a command is "printed"..

Pseudo-Pure code:

Code: Select all

Cmd$=RunProgram("find /") ; List all files on the root partition
..
..
SetGadgetText(#EDITOR_GADGET, Cmd$)
So, RunProgram would return the output of the program into Cmd$, and then it would SetGadgetText for the EditorGadget to have the Cmd$ text..

But note: The command outputs new data every second, so my EditorGadget should be updated all-the-time, so I can see the result of the command in "real-time"..

Thanks for any help!

Posted: Tue Feb 20, 2007 2:56 pm
by walker
1st...don't use find unless you use it only on your own machine... find does not work as expected on other distros or even it isn't installed (not a LSB specific command)

2nd: did you ever read the manual? Cmd$ is NOT the returned output of your command.. if you use it in this way, you'll get a compiler error (trying to write a numeric value....)

3rd: which Version of PB do you use as this is important for Runprogram as there are essential changes from 3.94 to 4.00 (and so for the help to give... :shock: )

If it's V4.00 (beta), try this:

Code: Select all

filename.s="find"
startpoint.s="/usr/bin"
mypgm= RunProgram("ls", "-A -l -R "+startpoint.s,"",#PB_Program_Read|#PB_Program_Open)
While ProgramRunning(mypgm)
   li.s=ReadProgramString(mypgm)
    If FindString(li,filename,1)
        output$ + li.s +#LF$
   EndIf
Wend
Trim(output$)
While Right(output$,1)=#LF$
    output$=Left(output$,Len(output$)-1)
Wend
Debug output$
modify it as you want... insted of using a variable you can direct the output to your editor gadget... for the parameters of the ls-command.... see the apropriate manual (man ls)

4th: Pseudo-code doesn't help much in most cases... posting a snippet, demonstrating the problem is much better (and no one has tp guess your problem... :wink: )

Posted: Tue Feb 20, 2007 3:27 pm
by merihevonen
1st: That was just an example.. I know that "find" doesn't come with all distros..

2nd: That was just P-S-E-U-D-O.. not real code

3rd: 4.00 beta.. forgot to mention.

Thanks for the code, but it freezes the application o_O

Posted: Tue Feb 20, 2007 3:33 pm
by merihevonen
I solved it!
Here's the code:

Code: Select all

hCmd=RunProgram("find", "/", ".", #PB_Program_Read|#PB_Program_Open)
While ProgramRunning(hCmd)
 If AvailableProgramOutput(hCmd)
  Debug ReadProgramString(hCmd)
 EndIf
Wend
Damn! It was so simple!.. I really need to relax a bit.. Thanks anyway

Posted: Tue Feb 20, 2007 7:07 pm
by walker
... no offense... :) (but from where the hell should I know that you know that? it was just a hint....)