GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||
GeezerVison is showing github.com — Enable transcription of native commands on non-Windows by SteveL-MSFT · Pull Request #4871 · PowerShell/PowerShell Conversation
Member
Transcription was relying on reading the screen buffer to record output from native commands. Fix #1920
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Steve Lee (SteveL-MSFT)
requested review from
Bruce Payette (BrucePay),
Dongbo Wang (daxian-dbw),
Jason Shirk (lzybkr) and
sergei (vors)
as code owners
Andrew (anmenaga)
suggested changes
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also need to check that PS error stream is empty.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will add
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, there's no reason to follow that pattern, I'm rewriting it as a scriptblock and any errors should just show up in the test run.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need newline in the end of file.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will add
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Dongbo Wang (daxian-dbw)
requested changes
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be made a static check so that we do it only once. And
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will change
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we want
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And form line 442 below, it indicates that we transcribe for native command only if
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, redirectInput shouldn't be true by default. Will fix. As for
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion:
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from line 444 below, it looks like a
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the catch for HostException was a mistake. Going through the code in the debugger, that exception isn't thrown.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
Steve Lee (@SteveL-MSFT) Could you please explain a little why redirecting the output/error would support transcribing in case that screen scraping is not supported? (just curious how it's done in that case) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Dongbo Wang (@daxian-dbw) from what I can tell in the code, anything that gets redirected gets transcribed anyways |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
722b161 to
c72288d
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think setting redirections for transcribing purpose should be done in the method CalculateIORedirection, and IMO it should be done at the end of that method -- after the existing logic of that method has run. For example, in case of running on the server side, redirectInput should always set to be true. Code like that should run even though screen scraping is not supported.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, will fix.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think there is a change of behavior here. Assuming _isTranscribing == $true and screen scraping is supported,
_scrapeHostOutput is true only if _runStandAlone is true, so this block will run only the native command is running standalone._startPosition is not even initialized.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Will fix
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove the else? The else if (Platform.IsWindowsDesktop && IsConsoleApplication(this.Path)) block doesn't necessarily set redirectOutput and redirectError to true.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
And please add a comment that explains why we need to set output/error redirection in such case.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
yup
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
These changes now can be reverted.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Will revert
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Andrew (@anmenaga) Can you please take a look again? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
015ca77 to
f769df1
Compare
f769df1 to
b63b374
Compare
|
Mark Kraus (@markekraus) the test failures are indicating the WebListener didn't start within the timeout. Is this something you're familiar with? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Steve Lee (@SteveL-MSFT) News to me. I will take a look. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Steve Lee (@SteveL-MSFT) This appears to be related to the change in this PR. It looks native execution inside a job is broken. WebListener runs expected behavior (working in beta.7): Actual behavior: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Mark Kraus (@markekraus) thanks! I'll take a look. The problem is that when run as a job obviously there's no console, so some of the console calls even on Windows throws other exceptions (and it's not just the Host.HostException from the old code) when the code is checking if screen scraping is supported. Added a test to test start-job with native command to cover this. Dongbo Wang (@daxian-dbw) Andrew (@anmenaga) can you take another look? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ot supported since screen buffer reading isn't supported, default to using redirected output
b63b374 to
2ff64d8
Compare
| catch (Exception) | ||
| { | ||
| // screen scraping not supported on non-Windows or as job | ||
| } |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think this check can still be done only once -- we do this check in CalculateIORedirection and only if _runStandAlone is true. Here the the code I propose:
private void CalculateIORedirection(out bool redirectOutput, out bool redirectError, out bool redirectInput) { ... if (NativeCommandProcessor.IsServerSide) { redirectInput = true; redirectOutput = true; redirectError = true; } else if (Platform.IsWindowsDesktop && IsConsoleApplication(this.Path)) { // On Windows desktops, if the command to run is a console application, // then allocate a console if there isn't one attached already... ConsoleVisibility.AllocateHiddenConsole(); if (ConsoleVisibility.AlwaysCaptureApplicationIO) { redirectOutput = true; redirectError = true; } } _runStandAlone = !redirectInput && !redirectOutput && !redirectError; // !!!!! NOTE !!!!! -- Unchanged until here if (_runStandAlone) { if (s_supportScreenScrape == null) { // Call GetBufferContents() to check and set s_supportScreenScrape to true or false accordingly. } // if screen scraping isn't supported, we enable redirection so that the output is still transcribed // as redirected output is always transcribed if (_isTranscribing && (false == s_supportScreenScrape)) { redirectOutput = true; redirectError = true; _runStandAlone = false; } } }
So the check of screen scraping support is done only if we are running the native command as standalone application.
In case of running it in a Job, I think the standard input and error are already redirected, so nothing needs to be done.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I see. I'll try that.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Transcription was relying on reading the screen buffer to record output from native commands. This resulted in an unhandled exception calling an unimplemented API on non-Windows. The fix is to use redirected output/error if reading the screen buffer is not supported. We check whether screen scraping is supported or not only when the application is running standalone.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.