Set working directory to current directory in Start-Job (#10920)

This commit is contained in:
Ilya
2019-10-30 14:22:45 -07:00
committed by Travis Plunk
parent f48a28eff2
commit 46957e54d0
2 changed files with 19 additions and 0 deletions
@@ -608,6 +608,17 @@ namespace Microsoft.PowerShell.Commands
ThrowTerminatingError(errorRecord);
}
if (WorkingDirectory == null)
{
try
{
WorkingDirectory = SessionState.Internal.CurrentLocation.Path;
}
catch (PSInvalidOperationException)
{
}
}
CommandDiscovery.AutoloadModulesWithJobSourceAdapters(this.Context, this.CommandOrigin);
if (ParameterSetName == DefinitionNameParameterSet)
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe 'Basic Job Tests' -Tags 'CI' {
BeforeAll {
# Make sure we do not have any jobs running
@@ -89,6 +90,13 @@ Describe 'Basic Job Tests' -Tags 'CI' {
{Start-Job -ScriptBlock { 1 + 1 } -WorkingDirectory $path} | Should -Throw -ErrorId $expectedErrorId
}
It 'Verifies that the current working directory is preserved' {
$job = Start-Job -ScriptBlock { $pwd }
$location = $job | Wait-Job | Receive-Job
$job | Remove-Job
$location.Path | Should -BeExactly $pwd.Path
}
It "Create job with native command" {
try {
$nativeJob = Start-job { pwsh -c 1+1 }