From a515b1b77aec825ef7750387ddacdd582f04cc77 Mon Sep 17 00:00:00 2001 From: Nana Lakshmanan Date: Sat, 13 Aug 2016 23:37:52 -0700 Subject: [PATCH] Fixing background jobs for Unix and Windows --- .../hostifaces/PowerShellProcessInstance.cs | 15 ++++++++++-- .../utils/CryptoUtils.cs | 4 ++++ test/powershell/engine/Jobs.Tests.ps1 | 23 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test/powershell/engine/Jobs.Tests.ps1 diff --git a/src/System.Management.Automation/engine/hostifaces/PowerShellProcessInstance.cs b/src/System.Management.Automation/engine/hostifaces/PowerShellProcessInstance.cs index d0c6ed3c176..c1aa0523c50 100644 --- a/src/System.Management.Automation/engine/hostifaces/PowerShellProcessInstance.cs +++ b/src/System.Management.Automation/engine/hostifaces/PowerShellProcessInstance.cs @@ -36,8 +36,13 @@ public sealed class PowerShellProcessInstance : IDisposable /// static PowerShellProcessInstance() { +#if UNIX + s_PSExePath = Path.Combine(Utils.GetApplicationBase(Utils.DefaultPowerShellShellID), + "powershell"); +#else s_PSExePath = Path.Combine(Utils.GetApplicationBase(Utils.DefaultPowerShellShellID), "powershell.exe"); +#endif } /// @@ -71,18 +76,22 @@ public PowerShellProcessInstance(Version powerShellVersion, PSCredential credent } } - string processArguments = string.Empty; +#if CORECLR + string processArguments = " -s -NoLogo -NoProfile"; +#else // Adding Version parameter to powershell.exe // Version parameter needs to go before all other parameters because the native layer looks for Version or // PSConsoleFile parameters before parsing other parameters. // The other parameters get parsed in the managed layer. Version tempVersion = powerShellVersion ?? PSVersionInfo.PSVersion; - processArguments = string.Format(CultureInfo.InvariantCulture, + string processArguments = string.Format(CultureInfo.InvariantCulture, "-Version {0}", new Version(tempVersion.Major, tempVersion.Minor)); processArguments = string.Format(CultureInfo.InvariantCulture, "{0} -s -NoLogo -NoProfile", processArguments); +#endif + if (initializationScript != null) { string scripBlockAsString = initializationScript.ToString(); @@ -106,7 +115,9 @@ public PowerShellProcessInstance(Version powerShellVersion, PSCredential credent RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, +#if !UNIX LoadUserProfile = true, +#endif }; if (credential != null) diff --git a/src/System.Management.Automation/utils/CryptoUtils.cs b/src/System.Management.Automation/utils/CryptoUtils.cs index 2536a530947..099257dca1b 100644 --- a/src/System.Management.Automation/utils/CryptoUtils.cs +++ b/src/System.Management.Automation/utils/CryptoUtils.cs @@ -1196,7 +1196,11 @@ internal class PSRemotingCryptoHelperServer : PSRemotingCryptoHelper /// internal PSRemotingCryptoHelperServer() { +#if UNIX + _rsaCryptoProvider = null; +#else _rsaCryptoProvider = PSRSACryptoServiceProvider.GetRSACryptoServiceProviderForServer(); +#endif } #endregion Constructors diff --git a/test/powershell/engine/Jobs.Tests.ps1 b/test/powershell/engine/Jobs.Tests.ps1 new file mode 100644 index 00000000000..789160d6b9c --- /dev/null +++ b/test/powershell/engine/Jobs.Tests.ps1 @@ -0,0 +1,23 @@ +Describe 'Basic Job Tests' -Tags 'CI' { + + BeforeAll { + $job = Start-Job {1} + } + + It 'Test job creation' { + $job | should not be $null + } + + It 'Test job State' { + Wait-Job $job -Timeout 60 + $job.JobStateInfo.State -eq 'Completed' | should be $true + } + + It 'Job output test' { + Receive-Job $job -wait | should be 1 + } + + AfterAll { + Remove-Job $job -Force + } +} \ No newline at end of file