Wait for command line to finish before executing next

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
martinjd
Newbie
Posts: 3
Joined: Fri Feb 15, 2013 10:04 pm

Wait for command line to finish before executing next

Post by martinjd » Fri Feb 15, 2013 10:25 pm

I have a SharePoint 2010 Management Powershell opened using Macro Scheduler and pass in a powershell script for it to execute. I then pass in another script for it to run. Ideally I would like to wait for the first script to complete before executing the Send command to start the second script.

Since the PowerShell cannot accept keyboard input it works out ok and the second script does not get run until the first finishes since the window is not able to accept the text. The issue is that once the first script finishes and the text for the second script is sent and the second script starts I then do a check to see if another routine should run which starts another program outside the PowerShell. This routine should not run until the second script completes.

I am not sure how to make Macro Scheduler wait for the second script to complete before calling the last routine. Is there a way to determine in a PowerShell or command line whether or not a command has completed?

Below is the code as it currently exists:

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1

Dialog>InstallSegment
object InstallSegment: TForm
  Left = 285
  Top = 115
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Segment Information'
  ClientHeight = 185
  ClientWidth = 278
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -14
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 120
  TextHeight = 16
  object LabelSegmentName: TLabel
    Left = 8
    Top = 16
    Width = 94
    Height = 16
    Caption = 'Segment Name'
  end
  object LabelEnvironment: TLabel
    Left = 8
    Top = 56
    Width = 74
    Height = 16
    Caption = 'Environment'
  end
  object TextSegment: TEdit
    Left = 112
    Top = 9
    Width = 73
    Height = 24
    TabOrder = 0
    TextHint = 'ie... AAAA, BBBB'
  end
  object ButtonInstall: tMSButton
    Left = 96
    Top = 144
    Width = 75
    Height = 25
    Caption = 'Install'
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object ComboBoxEnvironmentType: tMSComboBox
    Left = 111
    Top = 56
    Width = 145
    Height = 24
    TabOrder = 2
    Text = 'Select one'
    Items.Strings = (
      'Local'
      'Development'
      'Test'
      'Demo'
      'Production')
    ListText = 'Local'#13#10'Development'#13#10'Test'#13#10'Demo'#13#10'Production'#13#10
  end
  object ButtonQuit: tMSButton
    Left = 184
    Top = 144
    Width = 75
    Height = 25
    Caption = 'Quit'
    TabOrder = 3
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object CheckBoxInstallReports: TCheckBox
    Left = 113
    Top = 103
    Width = 136
    Height = 17
    Caption = 'Install Reports'
    Checked = True
    State = cbChecked
    TabOrder = 12
  end
end
EndDialog>InstallSegment

AddDialogHandler>InstallSegment,ButtonInstall,OnClick,DoInstall
AddDialogHandler>InstallSegment,ButtonQuit,OnClick,DoQuit
Show>InstallSegment,

// User quits install
SRT>DoQuit
  CloseDialog>InstallSegment
END>DoQuit

// User begins install
SRT>DoInstall
GetDialogProperty>InstallSegment,TextSegment,Text,varSegment
GetDialogProperty>InstallSegment,ComboBoxEnvironmentType,Text,varEnvironment
GetDialogProperty>InstallSegment,CheckBoxInstallReports,Checked,varInstallReports

If>{(%varEnvironment% = "Local")}
    StringReplace>varEnvironment,Local,local,varEnvironment
ENDIF
If>{(%varEnvironment% = "Development")}
    StringReplace>varEnvironment,Development,dev,varEnvironment
ENDIF
If>{(%varEnvironment% = "Test")}
    StringReplace>varEnvironment,Test,test,varEnvironment
ENDIF
If>{(%varEnvironment% = "Demo")}
    StringReplace>varEnvironment,Demo,demo,varEnvironment
ENDIF
If>{(%varEnvironment% = "Production")}
    StringReplace>varEnvironment,Production,,varEnvironment
ENDIF
Let>varProtocol=https://
LowerCase>%varSegment%,varSegmentLowerCase
Let>varUrl=%varProtocol%%varSegmentLowerCase%%varEnvironment%.mysite.com
Let>RP_WINDOWMODE=1
Let>RP_WIN64PROCESS=1
RunProgram>C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -NoExit   " & ' C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\\sharepoint.ps1 ' "
Wait 3
SetFocus>Administrator: C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe
SendText>cd "C:\Program Files (x86)\XXXX\XXXXX"
Press Enter
Send>.\i
Press Tab
Wait>1
Press Enter
Wait>2
Send>cd ..
Press Enter
Send>cd %varSegment%
Press Enter
Wait>2
// This should not occur until the previous script has completed
// however since the PowerShell cannot accept the command it is
// queued until the previous command completes.
Send>.\install_%varSegment%
Press Tab
Press Space
Send> %varUrl%
Wait>2
Press Enter
// This should not occur until the previous script has completed
// but I need to figure out how to tell Macro Scheduler to wait
// for the previous script to complete first.

// Install reports if the box is checked
If>{(%varInstallReports% = "True")}
GoSub>InstallReports
ENDIF
END>DoInstall


// Should not run until all scripts in DoInstall have completed
SRT>InstallReports
  // Call external program to install reports
END>InstallReports





Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sat Feb 16, 2013 12:51 am

I haven't examined your code in great detail, but have you tried using the RP_WAIT system variable?

Let>RP_WAIT=1

martinjd
Newbie
Posts: 3
Joined: Fri Feb 15, 2013 10:04 pm

Post by martinjd » Mon Feb 18, 2013 8:56 pm

If I use RP_WAIT =1 then the commands that are to be entered into the powershell are not executed.

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Feb 19, 2013 12:34 am

Perhaps you could use one of the text capture functions like GetWindowTextEx> to acquire the window text then parse the text to determine how the script is doing.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts