Jump to content

Runwait and @COMSPEC


gertsolo
 Share

Recommended Posts

Hey,

I'm writing a script that starts a cmd box which starts an executable:

RunWait(@COMSPEC & " /c DoSomeThing " )

This executable keeps looping. I want to stop it but this is prevented with the RunWait command which....waits. The problem is that I can't run that executable once. It keeps looping in that com box.

So if I just use the RUN command, the cmd box appears and dissapears immediately without running the DoSomeThing command.

How can I stop that command after a time?

Second question: can I run a command line in background?

thx.

Edited by gertsolo

The more you learn, the less you know.

Link to comment
Share on other sites

1.

TimerInit()
TimerDiff()
ProcessClose()
Thx Rasim,

I see what you mean, but where should I put that? As soon as I start the RunWait it hangs on that line, no?

Or should I use the Run command with the timer, and if so, how?

thx

The more you learn, the less you know.

Link to comment
Share on other sites

gertsolo

Example:

Dim $ReadOut

$timer = TimerInit()

$PID = Run(@ComSpec & " /c dir c:\ /b /s", @SystemDir, @SW_HIDE, 2 + 4)

While 1
    If TimerDiff($timer) > 1000 Then ;If timer difference more than 1 sec
        ProcessClose($PID) ;close process
        ExitLoop ;Exit from loop
    EndIf
    
    $ReadOut &= StdoutRead($PID)
    If @error Then ExitLoop
WEnd

MsgBox(0, "", $ReadOut)
Link to comment
Share on other sites

Thanks Rasim,

that totally did the job ;)

Can different command lines be run in that way. I mean within the same dos box?

I need to run a few commands after each other in the same box, all in background.

For example a ftp sequence: login, sending files etc...

rgds,

Edited by gertsolo

The more you learn, the less you know.

Link to comment
Share on other sites

gertsolo

Something like this:

Dim $aPID[3] = [" /c dir c:\ /b /s", " /c dir d:\ /b /s", " /c dir e:\ /b /s"] ;few commands

For $i = 0 To UBound($aPID) - 1
    $aPID[$i] = Run(@ComSpec & $aPID[$i], @SystemDir, @SW_HIDE, 2 + 4)
Next

$timer = TimerInit()

While 1
    If TimerDiff($timer) > 1000 Then ;If timer difference more than 1 sec
        _Terminate($aPID) ;close process
        ExitLoop ;Exit from loop
    EndIf
WEnd

Func _Terminate($aPID)
    For $i = 0 To UBound($aPID) - 1
        ProcessClose($aPID[$i])
    Next
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...