Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.
Closed
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
13 changes: 13 additions & 0 deletions src/Microsoft.DotNet.Cli.Utils/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class Command : ICommand

private bool _running = false;

private string _pidFile;

private Command(CommandSpec commandSpec)
{
var psi = new ProcessStartInfo
Expand Down Expand Up @@ -101,6 +103,11 @@ public CommandResult Execute()
_process.Start();

Reporter.Verbose.WriteLine($"Process ID: {_process.Id}");
if (!string.IsNullOrEmpty(_pidFile))
{
Reporter.Verbose.WriteLine($"Process ID (PID) file: {_pidFile}");
File.WriteAllText(_pidFile, _process.Id.ToString());
}

var threadOut = _stdOut.BeginRead(_process.StandardOutput);
var threadErr = _stdErr.BeginRead(_process.StandardError);
Expand Down Expand Up @@ -136,6 +143,12 @@ public ICommand WorkingDirectory(string projectDirectory)
return this;
}

public ICommand PidFile(string file)
{
_pidFile = file;
return this;
}

public ICommand EnvironmentVariable(string name, string value)
{
#if NET451
Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.DotNet.Cli.Utils/ICommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public interface ICommand

ICommand WorkingDirectory(string projectDirectory);

ICommand PidFile(string file);

ICommand EnvironmentVariable(string name, string value);

ICommand CaptureStdOut();
Expand Down
1 change: 1 addition & 0 deletions src/dotnet/commands/dotnet-run/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static int Run(string[] args)
syntax.DefineOption("f|framework", ref runCmd.Framework, "Compile a specific framework");
syntax.DefineOption("c|configuration", ref runCmd.Configuration, "Configuration under which to build");
syntax.DefineOption("p|project", ref runCmd.Project, "The path to the project to run (defaults to the current directory). Can be a path to a project.json or a project directory");
syntax.DefineOption("pf|pid-file", ref runCmd.PidFile, "A file that contains the process id of the executed application");

This comment was marked as spam.

This comment was marked as spam.


syntax.DefineOption("h|help", ref help, "Help for compile native.");

Expand Down
2 changes: 2 additions & 0 deletions src/dotnet/commands/dotnet-run/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public partial class RunCommand
public string Framework = null;
public string Configuration = null;
public string Project = null;
public string PidFile = null;
public IReadOnlyList<string> Args = null;

ProjectContext _context;
Expand Down Expand Up @@ -150,6 +151,7 @@ private int RunExecutable()
.ForwardStdOut()
.ForwardStdErr()
.EnvironmentVariable("DOTNET_HOME", dotnetHome)
.PidFile(PidFile)
.Execute()
.ExitCode;

Expand Down