Can I monitor a shell?

I’ve used both Shells and Threads with generally good results. Web though is a different animal. Here’s what I’m trying to do. I have a test shell script which performs a simple directory listing every 5 seconds a dozen times (in other words…a “lengthy” shell process) – I want to kick off this shell command from a web app…. and then I want to update a text box on my web app whenever I have “data available” or “regularly” via a timer.

I have good results with shell mode = “0” since the app waits until the shell command has completed…and then I just take shell.result and throw it in the text box. But I don’t want the user to wait until “everything” is complete before getting feedback.

I hoped I could just execute the shell command with mode = “1” – and then just wait for data available. Since this is a Web App after all…I figured I may need to use a timer to specifically cause the web app to communicate with the server. I haven’t got that working either.

Any pearls of wisdom? (I know I could run each directory listing as a separate shell command….this is just a TEST operation so I can experiment with how to monitor any single long running shell command).

Mode 1 will return data as it’s available, but often CLI’s will do that in one shot. So let’s say your directory had 100,000 items in it. ls will return all 100k items, not, say, 1,000 items at a time, so your code in DataAvailable will be dealing with all items.

Other CLI’s will return text as they go making it more suitable for Mode 1/2, but even this case isn’t bad as it will not lock up the UI while the data is being gathered.

Have you tried this via a Web App? My web App doesn’t seem to see the “data available” or “complete” events.
s = new LinuxShell
s.mode = 1
s.Execute(“ls -l”)

My “LinuxShell” class has a MsgBox(me.Readall) in the “DataAvailable” and “Complete” Event Handlers.
It’s not like I really expected the WebApp to see these events….but…it would be nice if it could.
I never see a message box at all.

I guess I could try updating. I am running on 2013 R3.2

Why not create a file with the output of an asynchronous shell instead of through result, that you can open at your convenience ? That way you do not need to wait or synchronize.

No, I haven’t tried it in a web app.

Ideally, I want the user to see output from the shell as it happens. I don’t want the app to be “frozen” until the shell command completes. So I want to run it asynchronously….but my user needs to know when it’s “done” – If I can’t see the “completed” event…then I need a Timer to monitor if the shell “is running”. I would have thought the timer could also force a "read all " on the shell….but I haven’t gotten that to work either (even on the simple fast directory listing I cited above). I did consider that I could run the the shell command sending all output into a file. Then my timer could periodically read the file. That just leaves the problem that I need to possibly create a unique output file name so that multiple users don’t run into each other…and then I need to place this file somewhere it will automatically get cleaned up…otherwise I have a bunch of old text files sitting around on the server. I expected there was some way I could get access to the results “captured” during the shell run event. I’ve used this on OS X and Windows stand alone apps with no issue. The Web app lets me code it…and doesn’t give me any warnings….and the documentation doesn’t say “it won’t work” – so I tried it…. and it doesn’t work. I don’t know if it’s a XOJO web limitation….or if it’s “me”. I saw the XOJO “push” implementation example…and thought….if the Server Side application can “Push” an update to the Web App…. just maybe it can raise an event from a asynchronous shell. I can dream, right?

It’s working! And without a timer??? Wahoo!!
I’m not even exactly sure why…. but what I changed was I placed a shell object directly on my main form (in the main thread). I had tried instantiating a shell in code….I couldn’t get that to work….I tried creating a global variable of shell class and using it…that didn’t seem to work. My web page comes up…. and I click my “go” button…and I get events when data is available and/or the shell command completes. I like it! So much fun it should be illegal :stuck_out_tongue: Thanks all for your input.

Probably your shell was going out of scope and dying quietly. Putting it on the webpage makes it more global in scope, so it lives long enough to complete its task.