2016-03-04 23:48:30 +01:00
|
|
|
Describe "Start-Process" {
|
2015-11-11 22:16:00 +01:00
|
|
|
$pingCommand = (Get-Command -CommandType Application ping)[0].Definition
|
2015-11-10 18:45:21 +01:00
|
|
|
$pingDirectory = Split-Path $pingCommand -Parent
|
2016-03-04 23:42:08 +01:00
|
|
|
$tempFile = Join-Path -Path $TestDrive -ChildPath PSTest
|
|
|
|
$assetsFile = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath SortTest.txt
|
2016-03-05 02:21:04 +01:00
|
|
|
if ($IsWindows) {
|
|
|
|
$pingParam = "-n 2 localhost"
|
2015-11-10 18:45:21 +01:00
|
|
|
}
|
2016-03-05 02:21:04 +01:00
|
|
|
elseif ($IsLinux -Or $IsOSX) {
|
|
|
|
$pingParam = "-c 2 localhost"
|
2015-11-10 18:45:21 +01:00
|
|
|
}
|
|
|
|
|
2016-04-14 19:05:51 +02:00
|
|
|
# Note that ProcessName may still be `powershell` due to dotnet/corefx#5378
|
|
|
|
# This has been fixed on Linux, but not on OS X
|
|
|
|
|
2015-11-10 18:45:21 +01:00
|
|
|
It "Should process arguments without error" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$process = Start-Process ping -ArgumentList $pingParam -PassThru
|
2015-11-10 18:45:21 +01:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$process.Length | Should Be 1
|
|
|
|
$process.Id | Should BeGreaterThan 1
|
2016-04-14 19:05:51 +02:00
|
|
|
# $process.ProcessName | Should Be "ping"
|
2015-11-10 18:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should work correctly when used with full path name" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$process = Start-Process $pingCommand -ArgumentList $pingParam -PassThru
|
2015-11-10 18:45:21 +01:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$process.Length | Should Be 1
|
|
|
|
$process.Id | Should BeGreaterThan 1
|
2016-04-14 19:05:51 +02:00
|
|
|
# $process.ProcessName | Should Be "ping"
|
2015-11-10 18:45:21 +01:00
|
|
|
}
|
2015-11-11 19:17:22 +01:00
|
|
|
|
2015-11-10 18:45:21 +01:00
|
|
|
It "Should invoke correct path when used with FilePath argument" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$process = Start-Process -FilePath $pingCommand -ArgumentList $pingParam -PassThru
|
2015-12-23 21:55:36 +01:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$process.Length | Should Be 1
|
|
|
|
$process.Id | Should BeGreaterThan 1
|
2016-04-14 19:05:51 +02:00
|
|
|
# $process.ProcessName | Should Be "ping"
|
2015-11-10 18:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should wait for command completion if used with Wait argument" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$process = Start-Process ping -ArgumentList $pingParam -Wait -PassThru
|
2015-11-10 18:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should work correctly with WorkingDirectory argument" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$process = Start-Process ping -WorkingDirectory $pingDirectory -ArgumentList $pingParam -PassThru
|
2015-11-10 18:45:21 +01:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$process.Length | Should Be 1
|
|
|
|
$process.Id | Should BeGreaterThan 1
|
2016-04-14 19:05:51 +02:00
|
|
|
# $process.ProcessName | Should Be "ping"
|
2015-11-10 18:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should should handle stderr redirection without error" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$process = Start-Process ping -ArgumentList $pingParam -PassThru -RedirectStandardError $tempFile
|
2015-11-10 18:45:21 +01:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$process.Length | Should Be 1
|
|
|
|
$process.Id | Should BeGreaterThan 1
|
2016-04-14 19:05:51 +02:00
|
|
|
# $process.ProcessName | Should Be "ping"
|
2015-11-10 18:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should should handle stdout redirection without error" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$process = Start-Process ping -ArgumentList $pingParam -Wait -RedirectStandardOutput $tempFile
|
|
|
|
$dirEntry = dir $tempFile
|
2015-12-22 04:14:48 +01:00
|
|
|
$dirEntry.Length | Should BeGreaterThan 0
|
2015-11-10 18:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should should handle stdin redirection without error" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$process = Start-Process sort -Wait -RedirectStandardOutput $tempFile -RedirectStandardInput $assetsFile
|
|
|
|
$dirEntry = dir $tempFile
|
2015-12-22 04:14:48 +01:00
|
|
|
$dirEntry.Length | Should BeGreaterThan 0
|
2015-11-10 18:45:21 +01:00
|
|
|
}
|
2016-02-04 17:43:51 +01:00
|
|
|
|
|
|
|
Remove-Item -Path $tempFile -Force
|
2015-11-10 18:45:21 +01:00
|
|
|
}
|