Page MenuHomePhabricator

Spawn a new Powershell session when running commands on Windows
AbandonedPublic

Authored by hach-que on Aug 28 2014, 9:04 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 13, 5:21 PM
Unknown Object (File)
Wed, Apr 3, 1:44 PM
Unknown Object (File)
Mar 4 2024, 11:19 PM
Unknown Object (File)
Feb 27 2024, 2:18 AM
Unknown Object (File)
Feb 19 2024, 2:17 PM
Unknown Object (File)
Feb 19 2024, 2:31 AM
Unknown Object (File)
Feb 19 2024, 2:14 AM
Unknown Object (File)
Feb 5 2024, 1:58 AM

Details

Summary

Ref T5985. This is intended to fix issues introduced when using Cygwin OpenSSHD on Windows. By spawning a new Powershell session and running the command there, all of the appropriate environment variables are set up correctly.

There doesn't appear to be any way of restoring all the correct environment variables and settings for an existing process either, so we can't just repair the current environment.

Test Plan

Jenga.gif (200×150 px, 509 KB)

I don't think this will break existing setups using Windows, but given how absolutely fragile configuration seems to be under Windows in the first place, I really have no idea.

NOTE: I'm probably going to spend some more time testing this in conjunction with D10214 to make sure everything works 100%.

Diff Detail

Repository
rP Phabricator
Branch
arcpatch-D10378
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 2414
Build 2418: [Placeholder Plan] Wait for 30 Seconds

Event Timeline

hach-que retitled this revision from to Spawn a new Powershell session when running commands on Windows.
hach-que updated this object.
hach-que edited the test plan for this revision. (Show Details)
hach-que added a reviewer: epriestley.
src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php
82–89

We can get rid of this nonsense now that Powershell is executing mkdir (and can escape the path properly).

src/applications/drydock/interface/command/DrydockSSHCommandInterface.php
70–71

I tried exit 1 here, but apparently Powershell ignores it and decides to just exit with an error code of 0 instead. So instead I'm throwing an exception which causes it to have an error code of 1, but unfortunately causes this message to get sent to stderr.

hach-que edited edge metadata.

Handle more scenarios in which Powershell can fail but exit with a code of 0.

Okay, this is like 99% okay and 1% Powershell still sucks

src/applications/drydock/interface/command/DrydockSSHCommandInterface.php
55–56

This prevents Powershell from wrapping lines (well, any lines shorter than 512 characters).

58–71

This copies the environment variables from a real Windows session and overrides the UNIX-like environment that Cygwin sets up.

82–86

This re-invokes Powershell with the command. The reason for this is that Powershell behaves differently with regard to exit codes and error handling from a command in these two scenarios:

powershell.exe -Command some_command
$script = @"

# prefix code here

some_command
"@

powershell.exe -EncodedCommand <encoded script>

Superseded by D13341, which removes all the "SSH on Windows" changes from this diff.