MedallionShell: Attaching to already running process

The idea is to extend curent Command.Run API by adding:

public static Command AttachTo(int processId)

which would internally use Process.GetProcessById.

What do you think?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Ok, thanks for all the information, I’ll keep you updated about the progress.

Having gone through the exercise, there’s actually a decent amount here. What do you think? Am I missing anything? Would this be helpful?

Yes, exactly. For me even having a common API is valuable enough, but resolving all this corner cases is much better.

For consistency, I’m imagining an API like:

public class Command
{
    public static bool TryAttachToProcessId(int processId, out Command command);
}

Although in my initial proposition I proposed different version, just a little bit later I’ve realized that the try version would be the best option, so you’ve actually taken words from my mouth. One could also think to return enum instead of bool with possible values:

enum AttachingResult
{
    Success, // obvious
    AttachedWithoutHandle, //  exit code will not be available
    Failure // obvious
}

One open question is what options we should allow for such an API. Many of the options provided for Command.Run don’t make sense in this context, but some (timeout, cancellationToken, throwOnError) DO make sense. Probably we’ll take a separate Action<AttachToProcessOptionsBuilder> for this API.

Good point.

Relatedly, should we add this to the Shell API? Probably for consistency, although likely it wouldn’t be used very often.

Same thoughts.