none
How to run two Cscripts from within a cmd asynchronous RRS feed

  • Question

  • Hi

    In a cmd file I have:

    C:\Windows\SysWOW64\cscript c:\csFolder\MOTOR1.vbs 2>> c:\csFolder\MOTORerror.txt
    C:\Windows\SysWOW64\cscript c:\csFolder\MOTOR2.vbs 2>> c:\csFolder\MOTORerror.txt

    My question is how to make the second script run immediately after the first start independently of the first ends

    Thanks


    Joao Simplicio Rodrigues


    Wednesday, September 6, 2017 1:17 AM

Answers

  • Better to use PowerShell than VBScript. You can use Start-Process to run processes asynchronously.

    As jrv pointed out, you can't reliably write output to the same text file from two separately executing asynchronous processes due to the race condition you're introducing. You will need to write to two separate output files and concatenate them when the processes complete.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, September 6, 2017 2:38 PM
    Moderator

All replies

  • use "start"

    start /?


    \_(ツ)_/


    • Edited by jrv Wednesday, September 6, 2017 1:26 AM
    Wednesday, September 6, 2017 1:26 AM
  • Must doing something wrong...

    Also try to make a cmd for each line and when start the second I get the message:

    "The process cannot access the file because it is being used by another process."

    Also made this script:

    Option Explicit
    
    Dim objShell, CURODIR, sysDIRO
    Set objShell = Wscript.CreateObject("WScript.Shell")
    CURODIR = "\\SERVER\csFOLDER\"
    
    objShell.Run "C:\Windows\SysWOW64\cscript " & CURODIR & "MOTOR1.vbs 2>> " & CURODIR & "MOTORESerror.txt"
    WScript.Sleep 1000
    objShell.Run "C:\Windows\SysWOW64\cscript " & CURODIR & "MOTOR2.vbs 2>> " & CURODIR & "MOTORESerror.txt"
    WScript.Sleep 1000
    objShell.Run "C:\Windows\SysWOW64\cscript " & CURODIR & "MOTOR3.vbs 2>> " & CURODIR & "MOTORESerror.txt"
    WScript.Sleep 1000
    objShell.Run "C:\Windows\SysWOW64\cscript " & CURODIR & "MOTOR4.vbs 2>> " & CURODIR & "MOTORESerror.txt"
    WScript.Sleep 1000
    Set objShell = Nothing
    WScript.Quit
    
    The four script are running but for test I force na error in the first and in the third and I get no message in the MOTORerror.txt

    I'm keep trying.

    but


    Joao Simplicio Rodrigues

    Wednesday, September 6, 2017 2:18 AM
  • Each script must have its own output file.  All of yours attempt to use the same file.


    \_(ツ)_/

    Wednesday, September 6, 2017 2:32 AM
  • Tried it's the same even with just one script...

    for some reason the cscript called within then "objShell.Run " isn't redirect the error output

    Also tried using > instead of >>

    Also tried add 1>

    Still fighting...

    In resume what I have to achive is getting five vbscripts running in a machine

    One is watching if the other four terminate with error and in that case make a sound and send a email...

    I'm just missing the error messages... Because I do this using wscript with //B parameter so that the process terminate and the "watcher" beeps and send the email.

    If I don't use the //B parameter the process doesn't terminate.


    Joao Simplicio Rodrigues


    Wednesday, September 6, 2017 3:00 AM
  • Sorry but I cannot decode what you are trying to ask.

    Try asking about one issue only.  You are asking a whole list of unrelated things.


    \_(ツ)_/

    Wednesday, September 6, 2017 3:14 AM
  • For some reason the cscript called within then "objShell.Run " doesn't redirect the error output.

    Joao Simplicio Rodrigues

    Wednesday, September 6, 2017 3:23 AM
  • Just for reference

    I thought the solution would be to use objShell.exec instead of objShell.Run and get the error message with something like this:  

    Set objShell = Wscript.CreateObject("WScript.Shell")

    Set result = objShell.Exec("C:\Windows\SysWOW64\cscript " & CURODIR & "MOTOR1.vbs") Do While result.Status = 0 WScript.Sleep 100 Loop WScript.Echo resultado.Status WScript.Echo resultado.StdErr.ReadAll 'have yet to write (add) in the MOTORESerror.txt WScript.Echo resultado.StdOut.ReadAll

    but unfortunately isn't asynchronous.


    Joao Simplicio Rodrigues


    Wednesday, September 6, 2017 9:17 AM
  • Better to use PowerShell than VBScript. You can use Start-Process to run processes asynchronously.

    As jrv pointed out, you can't reliably write output to the same text file from two separately executing asynchronous processes due to the race condition you're introducing. You will need to write to two separate output files and concatenate them when the processes complete.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, September 6, 2017 2:38 PM
    Moderator