public static System.Diagnostics.Process? Start(System.Diagnostics.ProcessStartInfo startInfo) { throw null; }
public static System.Diagnostics.Process Start(string fileName) { throw null; }
public static System.Diagnostics.Process Start(string fileName, string arguments) { throw null; }
+ public static System.Diagnostics.Process Start(string fileName, System.Collections.Generic.IEnumerable<string> arguments) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public static System.Diagnostics.Process? Start(string fileName, string userName, System.Security.SecureString password, string domain) { throw null; }
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.Versioning;
+using System.Collections.Generic;
namespace System.Diagnostics
{
return Start(new ProcessStartInfo(fileName, arguments))!;
}
+ /// <summary>
+ /// Starts a process resource by specifying the name of an application and a set of command line arguments
+ /// </summary>
+ public static Process Start(string fileName, IEnumerable<string> arguments)
+ {
+ if (fileName == null)
+ throw new ArgumentNullException(nameof(fileName));
+ if (arguments == null)
+ throw new ArgumentNullException(nameof(arguments));
+
+ var startInfo = new ProcessStartInfo(fileName);
+ foreach (string argument in arguments)
+ {
+ startInfo.ArgumentList.Add(argument);
+ }
+
+ return Start(startInfo)!;
+ }
+
/// <devdoc>
/// <para>
/// Starts a process resource specified by the process start
}
}
+ [Fact]
+ public void Start_ThrowsArgumentNullExceptionForNullFileName()
+ {
+ Assert.Throws<ArgumentNullException>("fileName", () => Process.Start(null, Enumerable.Repeat("notNull", 1)));
+ }
+
+ [Fact]
+ public void Start_ThrowsArgumentNullExceptionForNullArgumentsList()
+ {
+ IEnumerable<string> @null = null;
+ Assert.Throws<ArgumentNullException>("arguments", () => Process.Start("notNull", @null));
+ }
+
+ [Fact]
+ [PlatformSpecific(TestPlatforms.Windows)] // cmd.exe is available only on Windows
+ public void Start_PassesArgumentsList_WhichGetsEscaped()
+ {
+ string folderNameWithSpaces = "folder name with spaces"; // this needs escaping
+ string fullPath = Path.Combine(TestDirectory, folderNameWithSpaces);
+ string[] arguments = new string[] { "/c", "mkdir", "-p", fullPath };
+
+ if (Directory.Exists(fullPath))
+ {
+ Directory.Delete(fullPath);
+ }
+
+ using (Process mkdir = Process.Start("cmd.exe", arguments))
+ {
+ Assert.Equal(arguments, mkdir.StartInfo.ArgumentList);
+
+ mkdir.WaitForExit(WaitInMS);
+
+ Assert.True(Directory.Exists(fullPath));
+ Directory.Delete(fullPath);
+ }
+ }
+
private IReadOnlyList<Process> CreateProcessTree()
{
(Process Value, string Message) rootResult = ListenForAnonymousPipeMessage(rootPipeHandleString =>