Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,14 @@ public bool IsSignedAndTrusted(string filename, IRequest request) {
public int StartProcess(string filename, string arguments, bool requiresElevation, out string standardOutput, IRequest requestObject) {
Process p = new Process();

if (requiresElevation) {
#if !CORECLR
if (requiresElevation)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mike Richmond (@mirichmo) can anything else be done here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoc Truong (@quoctruong) this is in PackageManagement. Do you need to do something alternative here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoc Truong (@quoctruong), Raghu Shantha (@raghushantha) I'm changing it for now since it will fail at runtime otherwise.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoc Truong (@quoctruong), Raghu Shantha (@raghushantha) You guys are more familiar with this code, can you please comment on how UseShellExecute = true can be avoided here for CoreCLR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoc Truong (@quoctruong) Raghu Shantha (@raghushantha) please be aware this might break you.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Andy Jordan (@andschwa), Dongbo Wang (@daxian-dbw) The change looks good to me.

@raghushantha Raghu Shantha (raghushantha) Jul 8, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Andy Jordan (@andschwa), Dongbo Wang (@daxian-dbw) - Only the MSU provider uses this code path. And MSU is N/A on Core platforms.

So the change is ok.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for verifying 😄

{
p.StartInfo.UseShellExecute = true;
} else {
}
else
#endif
{
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
}
Expand Down
21 changes: 10 additions & 11 deletions src/System.Management.Automation/help/HelpCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,18 +699,17 @@ private void LaunchOnlineHelp(Uri uriToLaunch)
{
this.WriteVerbose(string.Format(CultureInfo.InvariantCulture, HelpDisplayStrings.OnlineHelpUri, uriToLaunch.OriginalString));
System.Diagnostics.Process browserProcess = new System.Diagnostics.Process();
browserProcess.StartInfo.UseShellExecute = true;
if (Platform.IsWindows)
{
browserProcess.StartInfo.FileName = uriToLaunch.OriginalString;
} else if (Platform.IsOSX) {
browserProcess.StartInfo.FileName = "open";
browserProcess.StartInfo.Arguments = uriToLaunch.OriginalString;
} else if (Platform.IsLinux) {
browserProcess.StartInfo.FileName = "xdg-open";
browserProcess.StartInfo.Arguments = uriToLaunch.OriginalString;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This came in as true in Source Depot. I'm unsure what it actually affects here; testing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey A (@ealexjordan) I know why #974 is broken on Windows. Same thing happened here. When this is false, it couldn't find an associated program to open the URI. But it has to be false on .NET Core.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes so much more sense now, when this is fixed then, I should be able to remove the pending on the invoke-item tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure there's a fix. UseShellExecute = true simply can't be used in CoreCLR. Researching alternative ways to get Windows to launch the shell. Perhaps we need to do something similar to Linux / OS X and launch, what, cmd.exe? I'm not sure.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a lot of searching (some of which led me right back to Invoke-Item) I found the solution to be cmd.exe /c "start /b "" "the target"".

#if LINUX
browserProcess.StartInfo.FileName = Platform.IsLinux ? "xdg-open" : /* OS X */ "open";
browserProcess.StartInfo.Arguments = uriToLaunch.OriginalString;
browserProcess.Start();
#elif CORECLR
throw new PlatformNotSupportedException();
#else
browserProcess.StartInfo.FileName = uriToLaunch.OriginalString;
browserProcess.Start();
#endif
}
catch (InvalidOperationException ioe)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1333,20 +1333,16 @@ protected override void InvokeDefaultAction(string path)
{
System.Diagnostics.Process invokeProcess = new System.Diagnostics.Process();

if (Platform.IsWindows)
{
System.Diagnostics.Process.Start(path);
}
else if (Platform.IsOSX) {
invokeProcess.StartInfo.FileName = "open";
invokeProcess.StartInfo.Arguments = path;
}
else if (Platform.IsLinux) {
invokeProcess.StartInfo.FileName = "xdg-open";
invokeProcess.StartInfo.Arguments = path;
}

#if LINUX
invokeProcess.StartInfo.FileName = Platform.IsLinux ? "xdg-open" : /* OS X */ "open";
invokeProcess.StartInfo.Arguments = path;
invokeProcess.Start();
#elif CORECLR
throw new PlatformNotSupportedException();
#else
invokeProcess.StartInfo.FileName = path;
invokeProcess.Start();
#endif
}
} // InvokeDefaultAction

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ using namespace System.Diagnostics

Describe "Invoke-Item" {

$tmpDirectory = $TestDrive
$testfile = "testfile.txt"
$testfolder = "newDirectory"
$testlink = "testlink"
$FullyQualifiedFile = Join-Path -Path $tmpDirectory -ChildPath $testfile
$FullyQualifiedFolder = Join-Path -Path $tmpDirectory -ChildPath $testfolder
$FullyQualifiedLink = Join-Path -Path $tmpDirectory -ChildPath $testlink

function NewProcessStartInfo([string]$CommandLine, [switch]$RedirectStdIn)
{
return [ProcessStartInfo]@{
Expand Down Expand Up @@ -39,38 +31,20 @@ Describe "Invoke-Item" {
}
}

function Clean-State
{
if (Test-Path $FullyQualifiedLink)
{
Remove-Item $FullyQualifiedLink -Force
}

if (Test-Path $FullyQualifiedFile)
{
Remove-Item $FullyQualifiedFile -Force
}

if (Test-Path $FullyQualifiedFolder)
{
Remove-Item $FullyQualifiedFolder -Force
}
}

BeforeAll {
$powershell = Join-Path -Path $PsHome -ChildPath "powershell"
Setup -File testfile.txt -Content "Hello World"
$testfile = Join-Path $TestDrive testfile.txt
}

#Both tests are pending due to a bug in Invoke-Item on Windows. Fixed for Linux

It "Should call the function without error" -Pending:$IsWindows {
{ New-Item -Name $testfile -Path $tmpDirectory -ItemType file } | Should Not Throw
}

It "Should invoke a text file without error" -Pending:$IsWindows {
$debugfn = NewProcessStartInfo "-noprofile ""``Invoke-Item $FullyQualifiedFile`n" -RedirectStdIn
It "Should invoke a text file without error" -Skip:($IsWindows -and $IsCore) {
$debugfn = NewProcessStartInfo "-noprofile ""``Invoke-Item $testfile`n" -RedirectStdIn
$process = RunPowerShell $debugfn
EnsureChildHasExited $process
$process.ExitCode | Should Be 0
}
}

It "Should throw not supported on Windows with .NET Core" -Skip:($IsLinux -or $IsOSX -or !$IsCore) {
{ Invoke-Item $testfile }| Should Throw "Operation is not supported on this platform."
}
}