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
F14362687: D10378.id24977.diff
Fri, Dec 20, 1:16 PM
Unknown Object (File)
Thu, Dec 19, 7:22 AM
Unknown Object (File)
Fri, Dec 13, 7:45 PM
Unknown Object (File)
Sun, Dec 8, 8:43 AM
Unknown Object (File)
Wed, Nov 27, 12:04 AM
Unknown Object (File)
Fri, Nov 22, 10:21 PM
Unknown Object (File)
Thu, Nov 21, 2:19 PM
Unknown Object (File)
Nov 18 2024, 9:45 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 2413
Build 2417: [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
66–67

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
51–52

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

54–67

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

92–96

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.