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 @@ -215,6 +215,7 @@ public sealed partial class ProcessStartInfo
public ProcessStartInfo() { }
public ProcessStartInfo(string fileName) { }
public ProcessStartInfo(string fileName, string arguments) { }
public ProcessStartInfo(string fileName, System.Collections.Generic.IEnumerable<string> arguments) { }
public System.Collections.ObjectModel.Collection<string> ArgumentList { get { throw null; } }
[System.Diagnostics.CodeAnalysis.AllowNullAttribute]
public string Arguments { get { throw null; } set { } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1327,16 +1327,7 @@ public static Process Start(string fileName, string arguments)
[SupportedOSPlatform("maccatalyst")]
public static Process Start(string fileName, IEnumerable<string> arguments)
{
ArgumentNullException.ThrowIfNull(fileName);
ArgumentNullException.ThrowIfNull(arguments);

var startInfo = new ProcessStartInfo(fileName);
foreach (string argument in arguments)
{
startInfo.ArgumentList.Add(argument);
}

return Start(startInfo)!;
return Start(new ProcessStartInfo(fileName, arguments))!;
}

/// <devdoc>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ public ProcessStartInfo(string fileName, string arguments)
_arguments = arguments;
}

/// <summary>
/// Specifies the name of the application that is to be started, as well as a set
/// of command line arguments to pass to the application.
/// </summary>
public ProcessStartInfo(string fileName, IEnumerable<string> arguments)
{
ArgumentNullException.ThrowIfNull(fileName);
ArgumentNullException.ThrowIfNull(arguments);

_fileName = fileName;
_argumentList = new Collection<string>(new List<string>(arguments));
}

/// <devdoc>
/// Specifies the set of command line arguments to use when starting the application.
/// </devdoc>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,15 +1257,33 @@ public void UninitializedArgumentList()
}

[Fact]
public void InitializeWithArgumentList()
public void InitializeWithArgumentList_Add()
{
ProcessStartInfo psi = new ProcessStartInfo("filename");
psi.ArgumentList.Add("arg1");
psi.ArgumentList.Add("arg2");

Assert.Equal(2, psi.ArgumentList.Count);
Assert.Equal("arg1", psi.ArgumentList[0]);
Assert.Equal("arg2", psi.ArgumentList[1]);
string[] args = new[] { "arg1", "arg2", " arg3", "arg4 ", "arg 5", $"arg{Environment.NewLine}6" };
foreach (string arg in args)
{
psi.ArgumentList.Add(arg);
}

Assert.Equal(args, psi.ArgumentList);
}

[Fact]
public void InitializeWithArgumentList_Enumerable()
{
string[] args = new[] { "arg1", "arg2", " arg3", "arg4 ", "arg 5", $"arg{Environment.NewLine}6" };
ProcessStartInfo psi = new ProcessStartInfo("filename", args);

Assert.Equal(args, psi.ArgumentList);
}

[Fact]
public void InitializeWithArgumentList_ThrowsArgumentNullException()
{
Assert.Throws<ArgumentNullException>("fileName", () => new ProcessStartInfo(null, new[] { "a", "b" }));
Assert.Throws<ArgumentNullException>("arguments", () => new ProcessStartInfo("a", (IEnumerable<string>)null));
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] // No Notepad on Nano
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ public static void ExitCode_VoidMainAppReturnsSetValue(int mode)
{
int expectedExitCode = 123;
const string AppName = "VoidMainWithExitCodeApp.exe";
var psi = new ProcessStartInfo();
psi.FileName = RemoteExecutor.HostRunner;
psi.Arguments = $"{AppName} {expectedExitCode} {mode}";

using (Process p = Process.Start(psi))
using (Process p = Process.Start(RemoteExecutor.HostRunner, new[] { AppName, expectedExitCode.ToString(), mode.ToString() }))
{
p.WaitForExit();
Assert.Equal(expectedExitCode, p.ExitCode);
Expand Down
4 changes: 1 addition & 3 deletions src/tests/Loader/binding/tracing/BinderTracingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,8 @@ private static bool RunSingleTest(MethodInfo method)

private static bool RunTestInSeparateProcess(MethodInfo method)
{
var startInfo = new ProcessStartInfo()
var startInfo = new ProcessStartInfo(Process.GetCurrentProcess().MainModule.FileName, new[] { Assembly.GetExecutingAssembly().Location, method.Name })
{
FileName = Process.GetCurrentProcess().MainModule.FileName,
Arguments = $"{Assembly.GetExecutingAssembly().Location} {method.Name}",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
Expand Down