3 回答

TA貢獻1735條經驗 獲得超5個贊
Lpinfo (CUPS) 解決方法:
using System.Diagnostics;
var startInfo = new ProcessStartInfo("lpstat", "-p")
{
RedirectStandardOutput = true,
CreateNoWindow = true
};
var process = Process.Start(startInfo);
var output = await process.StandardOutput.ReadToEndAsync();
var printerNames = output.Split("\n", StringSplitOptions.RemoveEmptyEntries)
.Select(line => line.Split(" ")[1])
.Where(name => !string.IsNullOrWhiteSpace(name))
.ToArray();
await process.WaitForExitAsync();
Console.WriteLine(string.Join("\n",printerNames));

TA貢獻1783條經驗 獲得超4個贊
對我來說聽起來像是 .NET Core 中的一個錯誤。
您使用什么版本的 .NET Core?
.NET Core 2.1(及更高版本)具有在 macOS/Linux 上實現查找 InstalledPrinters 的代碼:https://github.com/dotnet/corefx/blob/master/src/System.Drawing.Common/src/System/Drawing /Printing/PrintingServices.Unix.cs
所以它應該可以工作(除非某個地方有錯誤)。
- 3 回答
- 0 關注
- 160 瀏覽
添加回答
舉報