程序检查打印机是否存在

时间:2021-11-25 00:11:38

I'm looking for a way to check if a printer exists on a Linux/Unix machine using a C or C++ program. Something like the following windows program:

我正在寻找一种检查打印机是否存在于Linux/Unix机器上使用C或c++程序的方法。类似于以下的windows程序:

BOOL IsPrinterExist(LPTSTR pPrinterName)
{
    HANDLE hPrinter = NULL;
    if(OpenPrinter(PRINTERNAME,&hPrinter,NULL))
    {
        ClosePrinter(hPrinter);
        hPrinter = NULL;
        return TRUE;
    }
    return FALSE;
}

I think I can do it using CUPS API, but I need something that will work on every machine without special installations, using the OS API. I know I can also use issue the lpstat -a command and read its output, but I'm looking for a way of doing it directly (do what lpstat -a does).

我认为我可以使用CUPS API实现它,但是我需要一些无需特殊安装就能在每台机器上工作的东西,使用OS API。我知道我也可以使用issue lpstat -a命令并读取它的输出,但是我正在寻找一种直接执行的方法(做lpstat -a所做的事情)。

1 个解决方案

#1


1  

Since CUPS is the de facto standard for printing on GNU/Linux systems, I wouldn't worry too much about "special installations": if CUPS isn't installed, the machine probably wouldn't be able to print anyway.

由于CUPS实际上是在GNU/Linux系统上打印的标准,所以我不会太担心“特殊安装”:如果不安装CUPS,机器可能无法打印。

To see how to use the CUPS API, take a look at lpstat's source.

要了解如何使用CUPS API,请查看lpstat的源代码。

#1


1  

Since CUPS is the de facto standard for printing on GNU/Linux systems, I wouldn't worry too much about "special installations": if CUPS isn't installed, the machine probably wouldn't be able to print anyway.

由于CUPS实际上是在GNU/Linux系统上打印的标准,所以我不会太担心“特殊安装”:如果不安装CUPS,机器可能无法打印。

To see how to use the CUPS API, take a look at lpstat's source.

要了解如何使用CUPS API,请查看lpstat的源代码。