mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Set working directory to current directory in Start-Job (#10920)
This commit is contained in:
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user