如何知道使用复制命令到本地主机打印机的打印过程何时成功完成?

How to know when printing process with copy command to localhost printer finished successfully?

目前我正在使用这种方式将 zpl 文件发送到打印机:

/C copy /B zplFile.zpl \localhost\GX420d

在 C# 中,我使用以下代码:

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = processName; //cmd
startInfo.Arguments = string.Format(processArgument, "tmp.txt");
process.StartInfo = startInfo;
process.Start();

一切正常,问题是我没有握手来知道打印过程何时成功完成,例如,如果我发送一个 zpl 文件并且打印机没有标签或断开连接,系统执行命令的假设打印过程成功完成。

我想知道标签是否打印成功。

注意 1:打印机是 GX420d,使用 USB 数据线。

有什么建议吗?

在此先致谢。

编辑中:

如果您在下图中看到有待打印的作业,好吧,作为解决方法,我可以使用 C# 在此列表中搜索,这可能吗?

List of pending jobs

好吧,也许这个解决方法会奏效。

http://www.codeproject.com/Articles/51085/Monitor-jobs-in-a-printer-queue-NET

如果你们有更好的选择来解决这个问题,我将不胜感激。

为了记录,我搜索了打印机作业,并计算了待处理的作业,如果大于零,我认为它失败了。

步骤是: 1.- 将 ZPL 文件发送到打印机。 2.- 使用 System.Threading.Thread.Sleep 等待预定时间。 3.- 搜索打印机待处理作业,如果计数 > 0 则它将失败,因为我假设标签未成功打印。

非常感谢大家花时间回答。如果您知道更好的解决方案,我将不胜感激。

检查一下,其中一个变量可能包含错误:

var process = new Process();
var startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = processName; //cmd
startInfo.Arguments = string.Format(processArgument, "tmp.txt");
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
process.StartInfo = startInfo;
process.Start();
string outputText = process.StandardOutput.ReadToEnd(); // Check this
string errorText = process.StandardError.ReadToEnd();   // Check this
int exitCode = process.ExitCode;                        // Check this
process.WaitForExit();
// In outputText is probably something here...
// In errorText is probably something here...
// In exitCode is probably something here...

请查看 ZPL Manual 中的 Host Query ~HQ ZPL 命令。

这不是一个完美的解决方案,但想法是您可以在发送 ZPL 进行打印之前或之后查询打印机的状态。