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 @@ -1331,7 +1331,22 @@ protected override void InvokeDefaultAction(string path)

if (ShouldProcess(resource, action))
{
System.Diagnostics.Process.Start(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;
}

invokeProcess.Start();

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.

Could you double check to make sure that on windows system, there is no two processes launched for invoke-item? Thanks.

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.

This PR is very old and this code has since been rewritten due to this not being supported on Windows at all. See #1325.

}
} // InvokeDefaultAction

Expand Down Expand Up @@ -7784,7 +7799,7 @@ public SwitchParameter Wait
private bool wait;

/// <summary>
/// When the �Raw switch is present, we don�t do any breaks on newlines,
/// When the Raw switch is present, we don't do any breaks on newlines,
/// and only emit one object to the pipeline: all of the content.
/// </summary>
[Parameter]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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]@{
FileName = $powershell
Arguments = $CommandLine
RedirectStandardInput = $RedirectStdIn
RedirectStandardOutput = $true
RedirectStandardError = $true
UseShellExecute = $false
}
}

function RunPowerShell([ProcessStartInfo]$debugfn)
{
$process = [Process]::Start($debugfn)
return $process
}

function EnsureChildHasExited([Process]$process, [int]$WaitTimeInMS = 15000)
{
$process.WaitForExit($WaitTimeInMS)

if (!$process.HasExited)
{
$process.HasExited | Should Be $true
$process.Kill()
}
}

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"
}

#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
$process = RunPowerShell $debugfn

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.

Do you need to launch a whole new PowerShell process for this? Can't you just launch Invoke-Item and check that it didn't throw?

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.

Synced offline: II was failing silently on Linux with defunct threads, which would cause the host process to exit with an error code. This is the correct test.

EnsureChildHasExited $process
$process.ExitCode | Should Be 0
}
}