Viewing bash/php scripts in real time
Posted
#1
(In Topic #1249)
Regular

I have a project that I've been working for awhile that consists of a main bash script that does several things in order including calling a few php scripts (database stuff) and a few Linux commands (find and comm) and then the script ends and I have a nice chunk of data to either ignore or insert into a mysql DB. What I'm trying to do is build a nice little Gambas GUI app that somehow can show me the progress of all this stuff that's happening in that bash script including the php scripts and Linux commands as well as launch the script itself. I'm aware of exec and shell and have used both but in those cases I was never looking to get any output from the scripts. So far my experiments with Shell and "To string" are not working as most times I don't see anything until the scripts is done or I just get nothing back at all or it crashes…etc. Is there a way to see what's going on in in the bash script real time and send to a gambas component like a textarea box? The process is generating a lot of text data so I assume that is a problem somehow.
BTW, I have experimented with just completely writing this project in pure Gambas and eliminating bash, php and Linux commands. The amount of text data generated that I tried getting into textarea components quickly crashed the app so I the experiment didn't last long as that is a show stopper.
Posted
Guru

rj71 said
Hi All,
I have a project that I've been working for awhile that consists of a main bash script that does several things in order including calling a few php scripts (database stuff) and a few Linux commands (find and comm) and then the script ends and I have a nice chunk of data to either ignore or insert into a mysql DB. What I'm trying to do is build a nice little Gambas GUI app that somehow can show me the progress of all this stuff that's happening in that bash script including the php scripts and Linux commands as well as launch the script itself. I'm aware of exec and shell and have used both but in those cases I was never looking to get any output from the scripts. So far my experiments with Shell and "To string" are not working as most times I don't see anything until the scripts is done or I just get nothing back at all or it crashes…etc. Is there a way to see what's going on in in the bash script real time and send to a gambas component like a textarea box? The process is generating a lot of text data so I assume that is a problem somehow.
BTW, I have experimented with just completely writing this project in pure Gambas and eliminating bash, php and Linux commands. The amount of text data generated that I tried getting into textarea components quickly crashed the app so I the experiment didn't last long as that is a show stopper.
Using "To String" with shell implies Wait and the command will not return any results till it is finished.
Use a Process handler with your Shell or Exec command
Then read the output in the Process_Read() event
Something like this… (edited)
Posted
Regular

BruceSteers said
rj71 said
Hi All,
I have a project that I've been working for awhile that consists of a main bash script that does several things in order including calling a few php scripts (database stuff) and a few Linux commands (find and comm) and then the script ends and I have a nice chunk of data to either ignore or insert into a mysql DB. What I'm trying to do is build a nice little Gambas GUI app that somehow can show me the progress of all this stuff that's happening in that bash script including the php scripts and Linux commands as well as launch the script itself. I'm aware of exec and shell and have used both but in those cases I was never looking to get any output from the scripts. So far my experiments with Shell and "To string" are not working as most times I don't see anything until the scripts is done or I just get nothing back at all or it crashes…etc. Is there a way to see what's going on in in the bash script real time and send to a gambas component like a textarea box? The process is generating a lot of text data so I assume that is a problem somehow.
BTW, I have experimented with just completely writing this project in pure Gambas and eliminating bash, php and Linux commands. The amount of text data generated that I tried getting into textarea components quickly crashed the app so I the experiment didn't last long as that is a show stopper.
Using "To String" with shell implies Wait and the command will not return any results till it is finished.
Use a Process handler with your Shell or Exec command
Then read the output in the Process_Read() event
Something like this…
Thanks Bruce! That's what I'm looking for although I think I may have done a poor job of asking my question. I'm looking for what your code does but printing it to a component (textarea…label?) on the form instead of the IDE console and seeing that data zipping by in real time. Maybe I'm approaching this the wrong way.
Posted
Regular

Posted
Guru

Posted
Regular

BruceSteers said
This is strange. I tried your new code and it's still printing to console even though "Print sOutput" is commented out. Nothing is populating the textarea component. I'm not sure what I'm doing wrong. I've been working on this project awhile and the whole thing has been a gigantic headache
Posted
Guru

hProc = Shell "/path/to/bash_script" For Input As "PROC"
Posted
Regular

BruceSteers said
Oops sorry use Input not Output
hProc = Shell "/path/to/bash_script" For Input As "PROC"
Posted
Guru

rj71 said
BruceSteers said
Oops sorry use Input not Output
hProc = Shell "/path/to/bash_script" For Input As "PROC"
no prob. works now. Another question though…how much data can be input into a textarea component? In some of my tests, there appears to be a clear limit as it ends up crashing the app but I don't know exactly how much it consumed before it crashed.
I didn't know there was a limit, i should think it's huge is there is.
maybe try clearing the textarea if it has grown too large.
Posted
Regular

BruceSteers said
rj71 said
BruceSteers said
Oops sorry use Input not Output
hProc = Shell "/path/to/bash_script" For Input As "PROC"
no prob. works now. Another question though…how much data can be input into a textarea component? In some of my tests, there appears to be a clear limit as it ends up crashing the app but I don't know exactly how much it consumed before it crashed.
I didn't know there was a limit, i should think it's huge is there is.
maybe try clearing the textarea if it has grown too large.
Some of the text files the process is generating are huge…like 4 to 5 gig text files. In one test, I tried scanning a drive (that's one part of this project) that had several million files, it went for 5 minutes or so before I got a segmentation fault. I'll try clearing the textarea like you suggest. Thanks Bruce!
Posted
Guru

Posted
Regular

BruceSteers said
I'll play with terminal view and see if that works. Thanks Bruce!
Posted
Regular

rj71 said
BruceSteers said
I'll play with terminal view and see if that works. Thanks Bruce!
Hey Bruce, I like the terminalview and have made some changes to my back end scripts to make this work. Just one small problem: with longer running scripts, the terminalview eventually stops scrolling down and I can't tell if the script has finished without scrolling down manually. Is there a way to auto scroll to the bottom until the script finishes?
Posted
Regular

Posted
Guru

rj71 said
rj71 said
BruceSteers said
I'll play with terminal view and see if that works. Thanks Bruce!
Hey Bruce, I like the terminalview and have made some changes to my back end scripts to make this work. Just one small problem: with longer running scripts, the terminalview eventually stops scrolling down and I can't tell if the script has finished without scrolling down manually. Is there a way to auto scroll to the bottom until the script finishes?
You got it, EnsureVisible
I found the same with TerminalView, mostly it's fine but occasionally it misses a scroll and then stops scrolling with the output.
I do something like this…
Code (gambas)
- TerminalView1.EnsureVisible()
- ' Detect when the command process ends and kill the event observer.
- ' PS. TerminalView1_Kill() does the same for this but we have a process event observer so I'll use that.
- hObs = Null
Posted
Regular

BruceSteers said
rj71 said
rj71 said
I'll play with terminal view and see if that works. Thanks Bruce!
Hey Bruce, I like the terminalview and have made some changes to my back end scripts to make this work. Just one small problem: with longer running scripts, the terminalview eventually stops scrolling down and I can't tell if the script has finished without scrolling down manually. Is there a way to auto scroll to the bottom until the script finishes?
You got it, EnsureVisible
I found the same with TerminalView, mostly it's fine but occasionally it misses a scroll and then stops scrolling with the output.
I do something like this…Code (gambas)
TerminalView1.EnsureVisible() ' Detect when the command process ends and kill the event observer. ' PS. TerminalView1_Kill() does the same for this but we have a process event observer so I'll use that. hObs = Null
Thanks Bruce. I'll try this bit of code because I did a test this morning and the terminalview stopped auto scrolling down on a very long running script. I'll take a look at it tomorrow because it's Indy 500 day and I got some meats to grill and some racing to watch
Posted
Regular

1 guest and 0 members have just viewed this.


