Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
making os specifix changes
Browse files Browse the repository at this point in the history
  • Loading branch information
maryamariyan committed Sep 1, 2017
1 parent 65ab5fd commit dc2d88f
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,62 @@ internal DateTime StartTimeCore
}
}

/// <summary>Gets arguments.</summary>
/// <param name="startInfo">The start info with which to start the process.</param>
private string[] GetArgs(ProcessStartInfo startInfo)
{
string[] argv;

if (startInfo.UseShellExecute)
{
argv = new string[3] { GetExecPath(), "-c", startInfo.FileName + " " + startInfo.Arguments};
}
else
{
argv = ParseArgv(startInfo);
}

return argv;
}

/// <summary>Gets execution path</summary>
private string GetExecPath()
{
string[] allowedProgramsToRun = { "xdg-open", "gnome-open", "kfmclient" };
string pathToProgram = string.Empty;

foreach (var program in allowedProgramsToRun)
{
pathToProgram = GetPathToProgram(program);
if (!string.IsNullOrEmpty(pathToProgram))
{
return pathToProgram + "/" + program;
}
}

return "/bin/sh";
}

/// <summary>
/// Gets the path to the program
/// </summary>
/// <param name="program"></param>
/// <returns></returns>
private string GetPathToProgram(string program)
{
string path = Environment.GetEnvironmentVariable("PATH");
string[] dirs = path.Split(":");
foreach (var dir in dirs)
{
string[] files = Directory.GetFiles(dir, program);
if (files.Length != 0)
{
return dir;
}
}
return string.Empty;
}

/// <summary>
/// Gets the amount of time the associated process has spent utilizing the CPU.
/// It is the sum of the <see cref='System.Diagnostics.Process.UserProcessorTime'/> and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ internal DateTime StartTimeCore
}
}

/// <summary>Gets arguments.</summary>
/// <param name="startInfo">The start info with which to start the process.</param>
private string[] GetArgs(ProcessStartInfo startInfo)
{
string[] argv;

if (startInfo.UseShellExecute)
{
argv = new string[3] { GetExecPath(), "--args", startInfo.FileName + " " + startInfo.Arguments};
}
else
{
argv = ParseArgv(startInfo);
}

return argv;
}

/// <summary>Gets execution path</summary>
private string GetExecPath()
{
return "/usr/bin/open";
}

/// <summary>
/// Gets the amount of time the associated process has spent utilizing the CPU.
/// It is the sum of the <see cref='System.Diagnostics.Process.UserProcessorTime'/> and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ private bool StartCore(ProcessStartInfo startInfo)
throw new InvalidOperationException(SR.CantRedirectStreams);
}

const string ShellPath = "/bin/sh";
var ShellPath = GetExecPath();

filename = ShellPath;
argv = new string[3] { ShellPath, "-c", startInfo.FileName + " " + startInfo.Arguments};
argv = GetArgs(startInfo);
}
else
{
Expand Down

0 comments on commit dc2d88f

Please sign in to comment.