smalltalk.ps1
author Jan Vrany <jan.vrany@labware.com>
Thu, 06 Aug 2020 09:33:44 +0100
branchjv
changeset 1626 62ac134d4f7f
parent 1554 43b993b853cf
permissions -rw-r--r--
`smalltalk`: remove trailing spaces from UNIX launcher script
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
     1
# This file inherits the licencing from the batch file (smalltalk.bat). (MIT)
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
     2
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
     3
# $executable        ... stx.com or .exe
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
     4
# $log_file          ... log file name with path
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
     5
# $log_file_encoding ... user defined encoding
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
     6
# $append_to_log     ... should the log file be appended? (TRUE/FALSE)
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
     7
# $cmd_close         ... sends either cmd /u /c (close cmd) or /u /k (cmd remains open)
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
     8
# $PowerShellVersion ... detected powershell version
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
     9
# $cmd_in_powershell ... should cmd.exe be used for stdout redirection? (TRUE/FALSE)
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    10
param($executable, $log_file, $log_file_encoding, $append_to_log, $cmd_close, $PowerShellVersion, $cmd_in_powershell, $stx_manual_switch_detected)
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    11
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    12
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    13
# ===========================================================================
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    14
# Reading directly from environment - due to the issues with passing quotes =
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    15
# ===========================================================================
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    16
# StX switches which are build during batch file execution $env:stx_switch
1553
815eb4c1a3ee Win32 launcher (v 1.6.7): empty switches allowed, detect manual switches when __binary.cmd_in_powershell=TRUE
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1552
diff changeset
    17
$stx_switch = [environment]::GetEnvironmentVariable("stx_switch")
1515
919fad4de40f version 1.4.6
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1514
diff changeset
    18
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    19
# PowerShell version detected during batch file execution  $env:powershell_version_all_functionality
1552
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    20
If (![String]::IsNullOrEmpty([environment]::GetEnvironmentVariable("powershell_version_all_functionality"))) {
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    21
    $stx_powershell_version = [environment]::GetEnvironmentVariable("powershell_version_all_functionality")
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    22
} Else {
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    23
    $host.ui.WriteErrorLine('[ERROR] Missing powershell detection variable -> powershell_version_all_functionality <-.')
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    24
    EXIT 1
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    25
}
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    26
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    27
# getting line width for the log file
1552
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    28
If (![String]::IsNullOrEmpty([environment]::GetEnvironmentVariable("stx.__numeric.log_file_width"))) {
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    29
    $log_file_width = [environment]::GetEnvironmentVariable("stx.__numeric.log_file_width")
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    30
} Else {
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    31
    $host.ui.WriteErrorLine('[ERROR] Missing -> stx.__numeric.log_file_width <- from smalltalk.cfg file.')
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    32
    EXIT 1
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    33
}
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    34
1548
b54f5916ed36 Win32 launcher (v 1.6.3): added new configuration option _numeric.start_sleep_in_debug
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1547
diff changeset
    35
# Defines start-sleep periods while running custom switches
1552
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    36
If (![String]::IsNullOrEmpty([environment]::GetEnvironmentVariable("stx.__numeric.start_sleep_in_debug"))) {
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    37
    $start_sleep_period = [environment]::GetEnvironmentVariable("stx.__numeric.start_sleep_in_debug")
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    38
} Else {
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    39
    $host.ui.WriteErrorLine('[ERROR] Missing -> stx.__numeric.start_sleep_in_debug <- from smalltalk.cfg file.')
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    40
    EXIT 1
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    41
}
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
    42
1548
b54f5916ed36 Win32 launcher (v 1.6.3): added new configuration option _numeric.start_sleep_in_debug
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1547
diff changeset
    43
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    44
# =======================================================
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    45
# Adjust all variables to PowerShell style $true/$false =
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    46
# =======================================================
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    47
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    48
If ([environment]::GetEnvironmentVariable("stx.__binary.colored_stdout") -eq 'TRUE') {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    49
    $use_color = $true
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    50
} Else {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    51
    $use_color = $false
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    52
}
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    53
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    54
If ($cmd_in_powershell -eq 'TRUE') {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    55
    $cmd_in_powershell = $true
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    56
} Else {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    57
    $cmd_in_powershell = $false
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    58
}
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    59
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    60
If ($append_to_log -eq 'TRUE') {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    61
    $append_to_log = $true
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    62
} Else {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    63
    $append_to_log = $false
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    64
}
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    65
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    66
If ($stx_manual_switch_detected -eq 'TRUE') {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    67
    $stx_manual_switch_detected = $true
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    68
} Else {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    69
    $stx_manual_switch_detected = $false
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    70
}
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    71
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    72
If ($use_color) {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    73
    # fastest way to init empty Hastable
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    74
    $saved_color = [System.Collections.Hashtable]@{}
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    75
    # save colors for later restore
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    76
    $window_private_data = (Get-Host).PrivateData
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    77
    $saved_color.Add('VerboseBackgroundColor', "$window_private_data.VerboseBackgroundColor") | Out-null; # Out-null for supressing the natural output
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    78
    $saved_color.Add('VerboseForegroundColor', "$window_private_data.VerboseForegroundColor") | Out-null
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    79
    $saved_color.Add('WarningBackgroundColor', "$window_private_data.WarningBackgroundColor") | Out-null
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    80
    $saved_color.Add('WarningForegroundColor', "$window_private_data.WarningForegroundColor") | Out-null
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    81
    $saved_color.Add('ErrorBackgroundColor', "$window_private_data.ErrorBackgroundColor") | Out-null
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    82
    $saved_color.Add('ErrorForegroundColor', "$window_private_data.ErrorForegroundColor") | Out-null
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    83
    #setting the user specified colors
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    84
    $window_private_data.VerboseBackgroundColor = [environment]::GetEnvironmentVariable("stx.stdout_VerboseBackgroundColor")
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    85
    $window_private_data.VerboseForegroundColor = [environment]::GetEnvironmentVariable("stx.stdout_VerboseForegroundColor")
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    86
    $window_private_data.WarningBackgroundColor = [environment]::GetEnvironmentVariable("stx.stdout_WarningBackgroundColor")
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    87
    $window_private_data.WarningForegroundColor = [environment]::GetEnvironmentVariable("stx.stdout_WarningForegroundColor")
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    88
    $window_private_data.ErrorBackgroundColor = [environment]::GetEnvironmentVariable("stx.stdout_ErrorBackgroundColor")
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    89
    $window_private_data.ErrorForegroundColor = [environment]::GetEnvironmentVariable("stx.stdout_ErrorForegroundColor")
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    90
} ElseIf ($cmd_in_powershell) {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    91
    $window_private_data = (Get-Host).PrivateData
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    92
    $window_private_data.VerboseBackgroundColor = 'Black'
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
    93
    $window_private_data.VerboseForegroundColor = 'Gray'
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    94
}
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    95
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    96
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    97
# ===========
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    98
# Functions =
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
    99
# ===========
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   100
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   101
# Function for correct $LASTEXITCODE to ERRORLEVEL passing
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   102
function ExitWithCode {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   103
    param (
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   104
        $exitcode
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   105
    )
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   106
    $host.SetShouldExit($exitcode)
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   107
    EXIT
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   108
} # end ExitWithCode
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   109
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   110
# To correctly write to stderr when launching from cmd.exe
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   111
# more at: https://stackoverflow.com/questions/4998173/how-do-i-write-to-standard-error-in-powershell/15669365#15669365
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   112
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   113
<#
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   114
 .SYNOPSIS
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   115
 Writes text to stderr when running in a regular console window,
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   116
 to the host''s error stream otherwise.
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   117
 
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   118
 .DESCRIPTION
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   119
 Writing to true stderr allows you to write a well-behaved CLI
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   120
 as a PS script that can be invoked from a batch file, for instance.
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   121
 
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   122
 Note that PS by default sends ALL its streams to *stdout* when invoked from 
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   123
 cmd.exe.
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   124
 
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   125
 This function acts similarly to Write-Host in that it simply calls
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   126
 .ToString() on its input; to get the default output format, invoke
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   127
 it via a pipeline and precede with Out-String.
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   128
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   129
#> 
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   130
# function Write-StdErr {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   131
#     param (
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   132
#         [PSObject] $input_object
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   133
#     )
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   134
#     $out_function = If ($Host.Name -eq 'ConsoleHost') { 
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   135
#         [Console]::Error.WriteLine
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   136
#     } Else {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   137
#         $host.ui.WriteErrorLine
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   138
#     }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   139
#     If ($input_object) {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   140
#         [void] $out_function.Invoke($input_object.ToString())
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   141
#     } Else {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   142
#         [string[]] $lines = @()
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   143
#         $Input | % { $lines += $_.ToString() }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   144
#         [void] $out_function.Invoke($lines -join "`r`n")
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   145
#     }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   146
# }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   147
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   148
# Print User message using String Array $message
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   149
function PrintMessage {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   150
    param(
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   151
        [Parameter( `
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   152
            Mandatory=$True, `
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   153
            Valuefrompipeline = $true)]
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   154
        [String]$message
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   155
    )
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   156
    begin {}
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   157
    process {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   158
        foreach ($Message in $Message) {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   159
            # Write-Host Considered Harmful - see http://www.jsnover.com/blog/2013/12/07/write-host-considered-harmful/
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   160
            # first way how to correctly write it
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   161
            #Write-host $message
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   162
            # highlights warning and error messages from StX VM!
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   163
            If ($line -match '\[error\]' -or $line -match '\[sigsegv\]') {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   164
                $host.ui.WriteErrorLine("$message")
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   165
            } ElseIf ($message -match '\[warn\]') {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   166
                Write-Warning $message
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   167
            } Else {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   168
                Write-Verbose -Message $message -Verbose
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   169
            } 
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   170
        }
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   171
    }
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   172
    end {}
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   173
} # end PrintMessage
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   174
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   175
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   176
# To correctly simultinously write to stdout and log file when using out-file!
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   177
# Colors the output based on string match
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   178
function Tee-Host {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   179
    Param (
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   180
        [Parameter(Mandatory=$true,
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   181
        ValueFromPipeline=$true,
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   182
        Position=0)]
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   183
        $message
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   184
    )
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   185
    begin {}
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   186
    Process {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   187
        # first way how to correctly write it
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   188
        # -EV is short (an alias) for -ErrorVariable
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   189
        If ($line -match '\[error\]' -or $line -match '\[sigsegv\]') {
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   190
            # this is printing error compatible with all PS versions
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   191
            $host.ui.WriteErrorLine("$message")
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   192
        } ElseIf ($message -match '\[warning\]') {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   193
            Write-Warning "$message"
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   194
        } Else {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   195
            Write-Verbose -Message "$message" -Verbose
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   196
        }
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   197
        # second correct way how to write it
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   198
        #$VerbosePreference = "Continue"
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   199
        #Write-Verbose $input_object; 
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   200
        return $message
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   201
    }
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   202
    end {}
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   203
} # end Tee-Host
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   204
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   205
# Synchronously (stdout & stderr) executes Smalltalk/X executable 
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   206
# stdout & stderr are redirected together via 2>&1 redirect
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   207
function InvokeCommandExecute {
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   208
    param(
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   209
       $execute_command
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   210
    )
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   211
    try {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   212
       "`n", "[INFO] Executing command: $execute_command" | PrintMessage
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   213
       Invoke-Expression -Command:$execute_command
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   214
       If ($lastexitcode -ne 0) {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   215
           $result = $result -join "`n"
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   216
           throw "$result `n"
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   217
       }
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   218
    }
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   219
    catch {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   220
        $window_private_data = (Get-Host).PrivateData
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   221
        # saving the original colors
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   222
        $saved_background_color = $window_private_data.ErrorBackgroundColor
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   223
        $saved_foreground_color = $window_private_data.ErrorForegroundColor
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   224
        # setting the new colors
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   225
        $window_private_data.ErrorBackgroundColor = 'White'
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   226
        $window_private_data.ErrorForegroundColor = 'Red'
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   227
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   228
        $host.ui.WriteErrorLine("[ERROR] happned in stx.com or PowerShell script - See log file: $log_file for more information.")
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   229
        Write-Error "`n`n[ERROR] Error from PowerShell:`n`n $_" 2>&1 | Tee-Host | Out-File -Append -Encoding $log_file_encoding -FilePath $log_file -Width $log_file_width
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   230
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   231
        $window_private_data.ErrorBackgroundColor = $saved_background_color
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   232
        $window_private_data.ErrorForegroundColor = $saved_foreground_color
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   233
    }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   234
} # end InvokeCommandExecute
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   235
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   236
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   237
# Asynchronously output stdout & stderr while executing Smalltalk/X executable
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   238
# Note: 
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   239
# 1) for now used only while having manual switches to smalltalk.bat
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   240
# 2) Is seems to be little bit slower than the Invoke-Expression, howerver Smalltalk/X GUI
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   241
#    appears sooner than all the messages are processed so the end speed should be comparable
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   242
# 3) for now used only when manual switches (inputed by user) are detected
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   243
# 4) Will output everything from stdout/stderr even when stx executable crashes or powershell encounters an error
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   244
#    (of course not closing the powershell window)
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   245
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   246
function DebugProcessExecute {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   247
    param(
1550
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   248
        [Parameter(Mandatory=$true, Position = 0)]
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   249
        [ValidateNotNullOrEmpty()]
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   250
        [String]$executable,
1550
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   251
        [Parameter(Mandatory=$true, Position = 1)]
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   252
        $stx_switch,
1550
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   253
        [Parameter(Mandatory=$true, Position = 2)]
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   254
        [String]$logging_function,
1550
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   255
        [Parameter(Mandatory=$true, Position = 3)]
1548
b54f5916ed36 Win32 launcher (v 1.6.3): added new configuration option _numeric.start_sleep_in_debug
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1547
diff changeset
   256
        [Int]$start_sleep_period,
1550
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   257
        [Parameter(Mandatory=$false, Position = 4)]
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   258
        [String]$verb,
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   259
        [Parameter(Mandatory=$false, Position = 5)]
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   260
        [System.Diagnostics.ProcessPriorityClass]$Priority = [System.Diagnostics.ProcessPriorityClass]::Normal
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   261
    )
1543
3e1e39d03968 Win32 launcher: adding correct encofing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1541
diff changeset
   262
    begin {
3e1e39d03968 Win32 launcher: adding correct encofing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1541
diff changeset
   263
        If ($log_file_encoding -eq 'ASCII') {
3e1e39d03968 Win32 launcher: adding correct encofing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1541
diff changeset
   264
            $output_encoding = New-Object -typename System.Text.ASCIIEncoding
3e1e39d03968 Win32 launcher: adding correct encofing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1541
diff changeset
   265
        } ElseIf ($log_file_encoding -eq 'UTF8') {
3e1e39d03968 Win32 launcher: adding correct encofing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1541
diff changeset
   266
            $output_encoding = New-Object -typename System.Text.UTF8Encoding
3e1e39d03968 Win32 launcher: adding correct encofing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1541
diff changeset
   267
        } ElseIf ($log_file_encoding -eq 'UTF16') {
3e1e39d03968 Win32 launcher: adding correct encofing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1541
diff changeset
   268
            $output_encoding = New-Object -typename System.Text.UnicodeEncoding
3e1e39d03968 Win32 launcher: adding correct encofing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1541
diff changeset
   269
        } ElseIf ($log_file_encoding -eq 'UTF32') {
3e1e39d03968 Win32 launcher: adding correct encofing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1541
diff changeset
   270
            $output_encoding = New-Object -typename System.Text.UTF32Encoding
3e1e39d03968 Win32 launcher: adding correct encofing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1541
diff changeset
   271
        }
3e1e39d03968 Win32 launcher: adding correct encofing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1541
diff changeset
   272
    }
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   273
    process {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   274
        try {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   275
           "`n", "[INFO] Executing asynchronously command: $executable $stx_switch | $logging_function" | PrintMessage
1543
3e1e39d03968 Win32 launcher: adding correct encofing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1541
diff changeset
   276
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   277
           # Setting process invocation parameters.
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   278
           $process_start_info = New-Object -TypeName System.Diagnostics.ProcessStartInfo
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   279
           $process_start_info.CreateNoWindow = $true
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   280
           $process_start_info.UseShellExecute = $false
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   281
           $process_start_info.RedirectStandardOutput = $true
1543
3e1e39d03968 Win32 launcher: adding correct encofing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1541
diff changeset
   282
           $process_start_info.StandardOutputEncoding = $output_encoding
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   283
           $process_start_info.RedirectStandardError = $true
1543
3e1e39d03968 Win32 launcher: adding correct encofing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1541
diff changeset
   284
           $process_start_info.StandardErrorEncoding = $output_encoding
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   285
           $process_start_info.FileName = $executable
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   286
           $process_start_info.Arguments = $stx_switch
1546
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   287
        
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   288
           If (![String]::IsNullOrEmpty($verb)) {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   289
               $process_start_info.Verb = $verb
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   290
           }
1546
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   291
        
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   292
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   293
           # Creating process object.
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   294
           $process = New-Object -TypeName System.Diagnostics.Process
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   295
           $process.StartInfo = $process_start_info
1550
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   296
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   297
           $passing_variable = new-object psobject -property @{file_logging = $logging_function}
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   298
1545
9679a56c46ef Win32 launcher: trying sync event
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1544
diff changeset
   299
           # Asynchronously listen for OutputDataReceived events on the process (stdout)
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   300
           # Note: To use all events without ForEach loop use: $event.SourceEventArgs.Data variable
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   301
           $outEvent = Register-ObjectEvent -InputObj $process `
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   302
                           -Event "OutputDataReceived" `
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   303
                           -Action `
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   304
            {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   305
                param
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   306
                (
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   307
                    [System.Object] $sender,
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   308
                    [System.Diagnostics.DataReceivedEventArgs] $events 
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   309
                )
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   310
                # Where to log
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   311
                $file_log = $Event.MessageData.file_logging
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   312
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   313
                ForEach  ($line in $events.data) {
1546
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   314
                    Write-Verbose "[stdout]: $line" -Verbose
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   315
                   
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   316
                    # write to the log file
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   317
                    $exec_with_logging = @"
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   318
Write-Output '[stdout]: $line' | $file_log
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   319
"@
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   320
                    Invoke-Expression -Command:$exec_with_logging
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   321
                    
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   322
                }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   323
            } -MessageData $passing_variable
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   324
            # /Out Listener - stdout
1543
3e1e39d03968 Win32 launcher: adding correct encofing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1541
diff changeset
   325
1545
9679a56c46ef Win32 launcher: trying sync event
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1544
diff changeset
   326
9679a56c46ef Win32 launcher: trying sync event
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1544
diff changeset
   327
            # # asynchronously listen for ErrorDataReceived events on the process (stderr)
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   328
            $errEvent = Register-ObjectEvent -InputObj $process `
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   329
            -Event "ErrorDataReceived" `
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   330
            -Action `
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   331
            {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   332
                param
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   333
                (
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   334
                    [System.Object] $sender,
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   335
                    [System.Diagnostics.DataReceivedEventArgs] $events
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   336
                ) 
1550
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   337
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   338
                $file_log = $Event.MessageData.file_logging
1550
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   339
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   340
                ForEach  ($line in $events.data) {
1550
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   341
1546
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   342
                    # $line = ("[stderr]:" + $line)
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   343
                    If ($line -match '\[error\]' -or $line -match '\[sigsegv\]') {
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   344
                        $host.ui.WriteErrorLine("$line")
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   345
                    } ElseIf ($line -match '\[warn\]') {
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   346
                        Write-Warning $line
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   347
                    } Else {
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   348
                        Write-Verbose -Message $line -Verbose
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   349
                    } 
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   350
 
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   351
                    # write to the log file
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   352
                    $exec_with_logging = @"
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   353
Write-Output '$line' | $file_log
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   354
"@
1546
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   355
                    Invoke-Expression -Command:$exec_with_logging
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   356
                }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   357
                
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   358
            } -MessageData $passing_variable
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   359
            #  Error Listener - stderr
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   360
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   361
           # Starting process with no return value
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   362
           [Void]$process.Start()
1550
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   363
           $process.PriorityClass = $Priority
1548
b54f5916ed36 Win32 launcher (v 1.6.3): added new configuration option _numeric.start_sleep_in_debug
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1547
diff changeset
   364
1546
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   365
           # Begin async read events
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   366
           $process.BeginOutputReadLine()
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   367
           $process.BeginErrorReadLine()
1548
b54f5916ed36 Win32 launcher (v 1.6.3): added new configuration option _numeric.start_sleep_in_debug
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1547
diff changeset
   368
1546
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   369
           # loop till application exited 
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   370
           # used for logging into the stdout/stderr
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   371
           # Note: the timeout has been tested for speed vs. process usage -> 50ms does not use CPU that much + the output is reasonably fast
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   372
           while (!$process.HasExited) { 
1550
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   373
               [System.Console]::Out.Flush()
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   374
               [System.Console]::Error.Flush()
1548
b54f5916ed36 Win32 launcher (v 1.6.3): added new configuration option _numeric.start_sleep_in_debug
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1547
diff changeset
   375
               Start-Sleep -Milliseconds $start_sleep_period
1546
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   376
           }
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   377
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   378
           $exit_code = $process.ExitCode
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   379
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   380
           If ($process.ExitCode -ne 0) {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   381
               $result = $result -join "`n"
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   382
               throw "$result `n"
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   383
           }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   384
        }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   385
        catch {
1547
b5b3a75bef0d Win32 launcher: adding stdout & stderr buffer flashing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1546
diff changeset
   386
            # The only reliable way to flush stderr is to produce an error message
b5b3a75bef0d Win32 launcher: adding stdout & stderr buffer flashing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1546
diff changeset
   387
            Write-Error -Message 'An error has occurred...'
b5b3a75bef0d Win32 launcher: adding stdout & stderr buffer flashing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1546
diff changeset
   388
b5b3a75bef0d Win32 launcher: adding stdout & stderr buffer flashing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1546
diff changeset
   389
            # If an error occurrences than wait till exit - all buffers are emptied
1550
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   390
            [System.Console]::Out.Flush()
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   391
            [System.Console]::Error.Flush()
1546
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   392
            $process.WaitForExit()
1547
b5b3a75bef0d Win32 launcher: adding stdout & stderr buffer flashing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1546
diff changeset
   393
            $process.CancelOutputRead()
b5b3a75bef0d Win32 launcher: adding stdout & stderr buffer flashing
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1546
diff changeset
   394
            $process.CancelErrorRead()
1546
04e3aa500a9c Win32 launcher: added .WaitForExit() method when error occures -> should flush the buffer when catch branch is entered
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1545
diff changeset
   395
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   396
            $window_private_data = (Get-Host).PrivateData
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   397
            # saving the original colors
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   398
            $saved_background_color = $window_private_data.ErrorBackgroundColor
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   399
            $saved_foreground_color = $window_private_data.ErrorForegroundColor
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   400
            # setting the new colors
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   401
            $window_private_data.ErrorBackgroundColor = 'White'
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   402
            $window_private_data.ErrorForegroundColor = 'Red'
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   403
        
1550
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   404
            $host.ui.WriteErrorLine("[ERROR] happened in stx.com or PowerShell script - See log file: $log_file for more information.")
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   405
            Write-Error "`n`n[ERROR] Error from PowerShell:`n`n $_" 2>&1 | Tee-Host | Out-File -Append -Encoding $log_file_encoding -FilePath $log_file -Width $log_file_width
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   406
        
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   407
            $window_private_data.ErrorBackgroundColor = $saved_background_color
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   408
            $window_private_data.ErrorForegroundColor = $saved_foreground_color
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   409
           
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   410
            # =======================================================
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   411
            # Add Catch section Separator when adding into the file =
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   412
            # =======================================================
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   413
            If (!$is_logfile_locked){
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   414
                If ($append_to_log) {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   415
                    Write-Output "`r`n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`r`n" | Out-File -Append -Encoding $log_file_encoding -FilePath $log_file -Width $log_file_width
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   416
                }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   417
            }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   418
        }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   419
        finally {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   420
           # Unregister events
1550
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   421
           If (($Null -ne $outEvent) -or ($Null -ne $errEvent)) {
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   422
               $outEvent.Name, $errEvent.Name |
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   423
               ForEach-Object {Unregister-Event -SourceIdentifier $_}
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   424
           }
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   425
        }
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   426
    }
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   427
    end {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   428
        return $exit_code
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   429
    } 
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   430
} # end DebugProcessExecute
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   431
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   432
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   433
# =============================
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   434
# check if log file is locked =
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   435
# =============================
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   436
function Test-FileLock {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   437
    param (
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   438
      [parameter(Mandatory=$true)][string]$path
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   439
    )
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   440
    $log_file = New-Object System.IO.FileInfo $path
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   441
    If ((Test-Path -Path $path) -eq $false) {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   442
        return $false
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   443
    }
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   444
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   445
    try {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   446
      $log_file_stream = $log_file.Open([System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None)
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   447
      If ($log_file_stream) {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   448
          $log_file_stream.Close()
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   449
      }
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   450
      $false
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   451
    } catch {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   452
      # file is locked by a process.
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   453
      return $true
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   454
    }
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   455
}
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   456
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   457
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   458
# ========================================================================
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   459
# Check if user did not start the PowerShell file directly - exit if yes =
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   460
# ========================================================================
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   461
If ([string]::IsNullOrEmpty($executable)) {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   462
    "`n", '[ERROR] You can not run this powershell script directly!', 'Execute batch file (.bat) instead.' | PrintMessage
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   463
    EXIT 1
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   464
}
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   465
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   466
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   467
# ====================================
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   468
# Checking the state of the log file =
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   469
# ====================================
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   470
# Must be done only once in the file in case 
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   471
# the file is unlocked before the second instance is closed
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   472
$is_logfile_locked = Test-FileLock($log_file)
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   473
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   474
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   475
# ================
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   476
# Stdout logging =
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   477
# ================
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   478
If ($is_logfile_locked){
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   479
    "`n", "[WARN] Log file $log_file in use.`n`n  !!NO LOGGING will be available for this Smalltalk/X instance!!" | PrintMessage
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   480
    '[INFO] Press any key to continue ...' | PrintMessage
1515
919fad4de40f version 1.4.6
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1514
diff changeset
   481
    # pause - waits for pressing any key
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   482
    $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-null
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   483
    If (!$cmd_in_powershell -and $stx_manual_switch_detected) {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   484
        $logging_function = 'Out-null'
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   485
    } Else {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   486
        $logging_function = 'Tee-Host | Out-null'
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   487
    }
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   488
} Else {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   489
    If (!$cmd_in_powershell -and $stx_manual_switch_detected) {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   490
        If ($append_to_log) {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   491
            $logging_function = "Out-File -Append -Encoding '$log_file_encoding' -FilePath '$log_file' -Width $log_file_width"
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   492
        } Else {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   493
            "`n", "[INFO] Creating a blank log file." | PrintMessage
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   494
            Write-Output $null | Out-File -Encoding $log_file_encoding -FilePath $log_file -Width $log_file_width
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   495
            $logging_function = "Out-File -Append -Encoding '$log_file_encoding' -FilePath '$log_file' -Width $log_file_width"
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   496
        }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   497
    } Else {  
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   498
        If ($append_to_log) {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   499
            $logging_function = "Tee-Host | Out-File -Append -Encoding $log_file_encoding -FilePath $log_file -Width $log_file_width"
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   500
        } Else {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   501
            $logging_function = "Tee-Host | Out-File -Encoding $log_file_encoding -FilePath $log_file -Width $log_file_width"
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   502
        }
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   503
    }
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   504
}
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   505
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   506
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   507
# ===========
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   508
# Execution =
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   509
# ===========
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   510
# Decide which stdout use - either powershell.exe or cmd.exe
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   511
If ($PowerShellVersion -ge $stx_powershell_version) {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   512
    # stdout output via powershell.exe
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   513
    If (!$cmd_in_powershell) {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   514
        # Debug powershell mode started with stdout and stderr separation!
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   515
        If ($stx_manual_switch_detected) {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   516
            # getting rid of all the double quotes around stx switches (were added in batch file)
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   517
            $stx_switch = $stx_switch -replace '"([-]+\w+)"', "`$1"
1550
df383905babc Win32 launcher (v 1.6.5): fixing batch code iregularietes after adding double quotes (especially with ^%%A etc.)
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1548
diff changeset
   518
1548
b54f5916ed36 Win32 launcher (v 1.6.3): added new configuration option _numeric.start_sleep_in_debug
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1547
diff changeset
   519
            $exit_code = DebugProcessExecute -executable $executable -stx_switch $stx_switch -logging_function $logging_function -start_sleep_period $start_sleep_period 
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   520
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   521
        } Else {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   522
            $command = @"
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   523
$executable $stx_switch 2>&1 | $logging_function
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   524
"@
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   525
            # Due to the PowerShell bug produces FullyQualifiedErrorId : NativeCommandError in the log file -> you can ignore it.
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   526
            # actual execution
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   527
            InvokeCommandExecute -execute_command $command
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   528
       }
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   529
    # stdout output via cmd.exe
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   530
    # --% was introduced in PowerShell 3.0, forces PowerShell to ignore all code afterwards
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   531
    # redirection from 9 - combined (all output combined into a single - easy to redirect stream) from Powershell
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   532
    # if manual switch detected force powershell to ignore all code afterwards
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   533
    } Else {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   534
        # check if manual switch detected
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   535
        If ($stx_manual_switch_detected) {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   536
            # if manual switch detected force powershell to ignore all code afterwards
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   537
            $stx_switch = "--% $stx_switch"
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   538
            $command = @"
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   539
cmd.exe $cmd_close $executable $stx_switch '2^>^&1' ^| $logging_function
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   540
"@
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   541
        } Else {
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   542
            # must replace double quotes in order for the cmd.exe to work correctly - cmd.exe requirement
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   543
            $stx_switch = $stx_switch -replace '"','^"'
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   544
            $command = @"
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   545
cmd.exe $cmd_close $executable $stx_switch '2>&1' | $logging_function
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   546
"@
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   547
        }
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   548
        
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   549
        # Due to the PowerShell bug may produce an error: "FullyQualifiedErrorId : NativeCommandError" in the log file -> you can ignore it.
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   550
        # actual execution
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   551
        Write-verbose -message $command -verbose
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   552
        InvokeCommandExecute -execute_command $command
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   553
    } # end Else
1552
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
   554
} Else { # legacy powershell - manual switches available via Asynchronous mode
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   555
    # stdout output via powershell.exe
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   556
    If (!$cmd_in_powershell) {
1552
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
   557
        If ($stx_manual_switch_detected) {
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
   558
            # getting rid of all the double quotes around stx switches (were added in batch file)
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
   559
            $stx_switch = $stx_switch -replace '"([-]+\w+)"', "`$1"
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
   560
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
   561
            $exit_code = DebugProcessExecute -executable $executable -stx_switch $stx_switch -logging_function $logging_function -start_sleep_period $start_sleep_period 
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
   562
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
   563
        } Else {
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
   564
            $command = @"
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   565
$executable $stx_switch 2>&1 | $logging_function
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   566
"@
1552
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
   567
            # Due to the PowerShell bug produces FullyQualifiedErrorId : NativeCommandError in the log file -> you can ignore it.
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
   568
            # actual execution
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
   569
            InvokeCommandExecute -execute_command $command
ba9701302d50 Win32 launcher (v 1.6.6): more validation, custom switches for PS 2.0
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1551
diff changeset
   570
        }
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   571
    # stdout output via cmd.exe
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   572
    } Else {
1553
815eb4c1a3ee Win32 launcher (v 1.6.7): empty switches allowed, detect manual switches when __binary.cmd_in_powershell=TRUE
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1552
diff changeset
   573
        If ($stx_manual_switch_detected) {
815eb4c1a3ee Win32 launcher (v 1.6.7): empty switches allowed, detect manual switches when __binary.cmd_in_powershell=TRUE
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1552
diff changeset
   574
            "`n", '[ERROR] You can not have -> __binary.cmd_in_powershell <- enabled and run manual switches with StX!' | PrintMessage
815eb4c1a3ee Win32 launcher (v 1.6.7): empty switches allowed, detect manual switches when __binary.cmd_in_powershell=TRUE
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1552
diff changeset
   575
            EXIT 1
815eb4c1a3ee Win32 launcher (v 1.6.7): empty switches allowed, detect manual switches when __binary.cmd_in_powershell=TRUE
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1552
diff changeset
   576
        } Else {
815eb4c1a3ee Win32 launcher (v 1.6.7): empty switches allowed, detect manual switches when __binary.cmd_in_powershell=TRUE
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1552
diff changeset
   577
            # must replace double quotes in order for the cmd.exe to work correctly??
815eb4c1a3ee Win32 launcher (v 1.6.7): empty switches allowed, detect manual switches when __binary.cmd_in_powershell=TRUE
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1552
diff changeset
   578
            $stx_switch = $stx_switch -replace '"','^"'
815eb4c1a3ee Win32 launcher (v 1.6.7): empty switches allowed, detect manual switches when __binary.cmd_in_powershell=TRUE
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1552
diff changeset
   579
            $command = @"
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   580
cmd.exe $cmd_close $executable $stx_switch '2>&1' | $logging_function
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   581
"@
1553
815eb4c1a3ee Win32 launcher (v 1.6.7): empty switches allowed, detect manual switches when __binary.cmd_in_powershell=TRUE
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1552
diff changeset
   582
           # Due to the PowerShell bug produces FullyQualifiedErrorId : NativeCommandError in the log file -> you can ignore it.
815eb4c1a3ee Win32 launcher (v 1.6.7): empty switches allowed, detect manual switches when __binary.cmd_in_powershell=TRUE
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1552
diff changeset
   583
           # actual execution
815eb4c1a3ee Win32 launcher (v 1.6.7): empty switches allowed, detect manual switches when __binary.cmd_in_powershell=TRUE
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1552
diff changeset
   584
           InvokeCommandExecute -execute_command $command
815eb4c1a3ee Win32 launcher (v 1.6.7): empty switches allowed, detect manual switches when __binary.cmd_in_powershell=TRUE
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1552
diff changeset
   585
        }
1514
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   586
    }
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   587
} # end if
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   588
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   589
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   590
# ======
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   591
# Exit =
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   592
# ======
4bdcdc52e55a Windows launcher improvement - starting is still done via smalltalk.bat
Patrik Svestka <patrik.svestka@gmail.com>
parents:
diff changeset
   593
# Sending exit code to calling batch file
1516
4b143ef7d138 version 1.4.8
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1515
diff changeset
   594
try {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   595
   #If ($cmd_in_powershell -or !$stx_manual_switch_detected){
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   596
   If (![string]::IsNullOrEmpty($exit_code)){
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   597
      "`n", "[INFO] Exiting from PowerShell with code $exit_code " | PrintMessage
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   598
      ExitWithCode -exitcode $exit_code
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   599
   } Else {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   600
      "`n", "[INFO] Exiting from PowerShell with code $LastExitCode " | PrintMessage
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   601
      ExitWithCode -exitcode $LastExitCode
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   602
   }
1516
4b143ef7d138 version 1.4.8
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1515
diff changeset
   603
}
4b143ef7d138 version 1.4.8
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1515
diff changeset
   604
catch {
1541
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   605
   $host.ui.WriteErrorLine("[ERROR] An error happend during exiting PowerShell.")
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   606
}
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   607
finally {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   608
    # =========================================
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   609
    # Add Separator when adding into the file =
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   610
    # =========================================
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   611
    If (!$is_logfile_locked){
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   612
        If ($append_to_log) {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   613
            Write-Output "`r`n=================================================================================================`r`n" | Out-File -Append -Encoding $log_file_encoding -FilePath $log_file -Width $log_file_width
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   614
        }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   615
    }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   616
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   617
    # ===============================
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   618
    # Restore original Shell colors =
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   619
    # ===============================
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   620
    If ($use_color) {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   621
        $window_private_data = (Get-Host).PrivateData
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   622
        ForEach($item in $saved_color.GetEnumerator()) {
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   623
            Set-Variable -name "$window_private_data.$($item.Key)" -Value "$($item.Value)"
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   624
        }
29481e235399 Win32 launcher (v 1.6.0): added System.Diagnostics.ProcessStartInfo for manual exection an dother fixes
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1540
diff changeset
   625
    }
1516
4b143ef7d138 version 1.4.8
Patrik Svestka <patrik.svestka@gmail.com>
parents: 1515
diff changeset
   626
}