Repository navigation
fix(harness): start child processes without NoDefaultCurrentDirectoryInExePath #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,26 @@ Describe 'Invoke-IslProcess' -Tag 'Unit', 'Private' { | |
| $result.StdOut.Trim() | Should-Be $TestDrive | ||
| } | ||
|
|
||
| It 'lets cmd.exe find a batch file in the working folder whatever the caller''s own shell setting' { | ||
| # NoDefaultCurrentDirectoryInExePath in the caller's environment stops cmd.exe looking in | ||
| # the working folder; the agent's cmd.exe has no such setting, so the child must not either | ||
| Set-Content -Path (Join-Path $TestDrive 'install.cmd') -Value '@echo ran' -Encoding ascii | ||
| $saved = $env:NoDefaultCurrentDirectoryInExePath | ||
| $env:NoDefaultCurrentDirectoryInExePath = '1' | ||
|
Owner
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. Set in the test's own process rather than mocked, because the thing under test is what the child inherits from the parent. Without the fix this exact run fails with "'install.cmd' is not recognized" (exit 1), which is how the problem showed up on a developer machine with the variable in the user environment. |
||
| try { | ||
| $result = Invoke-Process @{ | ||
| FilePath = $script:Cmd; Arguments = '/C "install.cmd"' | ||
| WorkingDirectory = $TestDrive; WorkFolder = $TestDrive | ||
| } | ||
| } | ||
| finally { | ||
| $env:NoDefaultCurrentDirectoryInExePath = $saved | ||
| } | ||
| $result.ExitCode | Should-Be 0 | ||
| $result.StdOut.Trim() | Should-Be 'ran' | ||
| $result.StdErr.Trim() | Should-Be '' | ||
| } | ||
|
|
||
| It 'closes stdin so a read returns instead of waiting' { | ||
| $result = Invoke-Process @{ | ||
| FilePath = $script:Cmd; Arguments = '/C set /p answer=name? & echo [%answer%]' | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed unconditionally rather than only when set: Remove on a missing key returns false and nothing else, and the task modes below are left alone on purpose. A scheduled task runs with the SYSTEM or the other account's environment, where a caller's per-user setting is not present, which is also the environment the agent's own cmd.exe has.