area-System.Consolehelp wantedos-linux
Repository metrics
- Stars
- (17,886 stars)
- PR merge metrics
- (Avg merge 12d 11h) (661 merged PRs in 30d)
Description
Description
it appears that an exited application hangs on to console handles after it exits
The application that I'm seeing in is the erlang program iex.
here's the code that shows off the issue.
using System;
using System.Diagnostics;
class Sample
{
public static void Main()
{
Console.CancelKeyPress += new ConsoleCancelEventHandler(handler);
ProcessStartInfo psi = new ProcessStartInfo("/usr/local/bin/iex");
//psi.RedirectStandardInput = true;
do
{
using(var p = Process.Start(psi)) {
p?.WaitForExit();
}
Console.WriteLine("\nproc has ended.\npress a key to run it again - 'q' to stop");
}
while (Console.ReadKey(true).KeyChar != 'q');
}
protected static void handler(object? sender, ConsoleCancelEventArgs args)
{
args.Cancel = true;
}
}
run the program and press CTRL-C twice (timing doesn't seem to matter here - quickly or slowly doesn't affect the outcome).
james@JamesiMac20 p025 % dotnet run
Erlang/OTP 24 [erts-12.0.3] [source] [64-bit] [smp:20:20] [ds:20:20:10] [async-threads:1] [jit] [dtrace]
Interactive Elixir (1.12.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>
BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
(l)oaded (v)ersion (k)ill (D)b-tables (d)istribution
^C
proc has ended
press a key to run it again - 'q' to stop
Unhandled exception. System.IO.IOException: The process cannot access the file because it is being used by another process.
at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
at Interop.CheckIo(Int64 result, String path, Boolean isDirectory, Func`2 errorRewriter)
at System.IO.StdInReader.ReadKey()
at System.IO.StdInReader.ReadKey(Boolean& previouslyProcessed)
at System.IO.SyncTextReader.ReadKey(Boolean& previouslyProcessed)
at System.ConsolePal.ReadKey(Boolean intercept)
at System.Console.ReadKey(Boolean intercept)
at Sample.Main() in /Users/james/src/projects/signal/p025/Program.cs:line 18
Configuration
net6.0
osx-x64
Model Name: iMac
Model Identifier: iMac20,1
Processor Name: 10-Core Intel Core i9
Processor Speed: 3.6 GHz
System Firmware Version: 1554.140.20.0.0 (iBridge: 18.16.14759.0.1,0)
Regression?
not sure
Other information
if the line which redirects StandardInput (or StandardOutput) is not commented out the error does not occur. i'm confused as to what's going on, the process has exited, but the error suggests that something is hanging on to a console handle.