[Gambas-user] Monitoring a process... Need help
M0E Lnx
m0e.lnx at ...626...
Mon Feb 4 19:40:53 CET 2008
Ok.. Been playing with this some more... an I can't help wondering....
Why should this not work?
MdlShellTest.Module
PUBLIC hShellProc as process
PUBLIC iStage as integer
PUBLIC sBuffer
PUBLIC FUNCTION sSysShell(sDir as string, iStep as integer)
DIM sShellLine as string
SELECT CASE iStep
CASE 0
sShellLine = "cd " & sDir & " || echo \'ERROR\'"
CASE 1
sShellLine = "ls -al " & sDir & " || echo \'ERROR\'"
' OTHER CASES HERE
END SELECT
hShellProc = SHELL sShellLine to sBuffer
iStage = iStep ' Update the publically visible stage here.
END
PUBLIC SUB Process_kill()
IF Instr(MdlShellTest.sBuffer, "ERROR") > 0 then
' Something went wrong during one of the shell commands
STOP EVENT ' Not sure this does anything here
ELSE
SELECT CASE MdlShellTest.iStage
CASE 0
MdlShellTest.sSysShell(sDir, 1) ' Trigger the next command
END SELECT
END IF
END
Is there a reason something liek that wouldn't work?
SELECT CASE MdlShellTest.iStage
END
On Feb 4, 2008 9:52 AM, M0E Lnx <m0e.lnx at ...626...> wrote:
> Yes I know... the code is now all messed up... I've been thinking this
> over and over...
> But it seems to me that I *should* be able to define one process, and
> run a bunch of shell commands via that one process.
>
> About your remarks... how do I tell it to trigger something when the
> process is done running?
> do I use the hShellProc_kill() event?...
> And do you mean that if I do that, I dont need a timer?
>
> The reason I ask is because it is not yet very clear to me... I
> thought you use the "Kill" to actually termintate a process, and it
> was my understanding that a process would returned a "Process.Stopped"
> property when it was done running...
>
> Please correct me if I'm wrong.
>
>
>
>
> On Feb 4, 2008 9:46 AM, Benoit Minisini <gambas at ...1...> wrote:
> >
> > On lundi 4 février 2008, M0E Lnx wrote:
> > > I'm trying to write a function to execute several shell commands in a
> > > given order. For instance, extract a compressed tarball, and then cd
> > > to it's extracted dir, and do "ls -al"
> > >
> > > Basically, what I want to do is execute several shell commands.
> > > I want to use One process for all shell commands instead of using one
> > > process for each command.
> > > I want to use one timer to monitor this one process... and as soon as
> > > it reports a Process.Stopped event, do some error checking, and if
> > > passed, execute the second command using the same Process variable i
> > > defined.
> > >
> > > The module file looks like this
> > >
> > > MdlShell
> > > Public hShellProc as Process
> > > Public iMdlStep as integer
> > > PUBLIC FUNCTION Extract(sPath as string, iFuncStep)
> > >
> > > DIM ShellLine as string
> > >
> > > ' The following commands will be triggered from a timer event in another
> > > form
> > >
> > > SELECT CASE iFuncStep
> > > CASE 0 ' First step
> > > ShellLine = "cd /tmp && tar xf " & sPath & " || echo \'ERROR\'"
> > >
> > > CASE 1 ' Second step
> > > shellLine = "cd /tmp && ls -a || echo \'ERROR\'"
> > >
> > > ' And the list would continue here
> > >
> > > END SELECT
> > >
> > > hShellProc = shell ShellLine for read ' execute the selected command
> > > iMdlStep = iFunctStep ' Make the last step available publically
> > >
> > > On a separate form, I have a timer setup.
> > > On this timer setup... on it's timer event I have this
> > >
> > > TmShellMon_timer()
> > >
> > >
> > > If MdlShell.hShellProc.State = Process.Stopped then
> > > Me.TmShellMon.Enabled = false
> > > ' Do some error checking here
> > > if instr(sBuffer, "ERROR") > 0 then
> > > STOP EVENT
> > > Else
> > >
> > > ' If no error is found then execute this
> > > SELECT CASE MdlShell.iMdlStep
> > >
> > > CASE 0 ' First step has ran... trigger next
> > > MdlShell.Extract(sPath, 1)
> > > CASE 1 ' Trigger 3rd step
> > > MdlShell.Extract(sPath, 2)
> > > ' And so on....
> > > END SELECT
> > > END IF
> > > END IF
> > >
> > > The problem With this is... for some reason it's not monitoring the
> > > process right... It's triggering a lot of the lines in the wrong
> > > sequence...
> > >
> > > Can anyone think of a way to fix this or a better way to do this?
> > > Please help
> > >
> >
> > As you don't give all your code, we can't guess what happens exactly.
> >
> > Anyway, a few remarks:
> >
> > - You always use one different process for each command, even if you store it
> > in the same variable.
> >
> > - To know when a process has stopped, you should use the "Kill" event, not a
> > timer.
> >
> > - STOP EVENT does nothing in a timer event.
> >
> > --
> > Benoit Minisini
> >
> > -------------------------------------------------------------------------
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
>
More information about the User
mailing list