I am trying to run an LPR command to print a PDF. The code I'm using is being executed from a button click in a windows forms application.
Code:
var command = @"lpr –S 192.168.1.245 –P DAILY C:\Test.pdf";
ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + command);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.RedirectStandardError = true;
procStartInfo.CreateNoWindow = true;
// start process
Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.Start();
proc.WaitForExit();
// read process output
string cmdError = proc.StandardError.ReadToEnd();
string cmdOutput = proc.StandardOutput.ReadToEnd();
The program is running as an x64 program, so it can find lpr program in the C:\Windows\System32 folder.
When the code executes the error string is empty and the output string contains the following (same output as if the command run had been lpr /?
)
Output:
Sends a print job to a network printer
Usage: lpr -S server -P printer [-C class] [-J job] [-o option] [-x] [-d] filename
Options: -S server Name or ipaddress of the host providing lpd service -P printer Name of the print queue -C class Job classification for use on the burst page -J job Job name to print on the burst page -o option Indicates type of the file (by default assumes a text file) -x Compatibility with SunOS 4.1.x and prior -d Send data file first
If I copy and paste the command exactly as it appears in the code and paste it into a command window, even if it's the SAME command window the application opened, it works fine.
Does anyone have any insight into why this would be happening? Thanks in advance!