title: C# - LPR Command to Print PDF Files
body: <p>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.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><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();
  </code></pre>
  
  <p>The program is running as an x64 program, so it can find lpr program in the C:\Windows\System32 folder.</p>
  
  <p>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 <code>lpr /?</code>)</p>
  
  <p><strong>Output:</strong></p>
  
  <blockquote>
    <p>Sends a print job to a network printer</p>
    
    <p>Usage: lpr -S server -P printer [-C class] [-J job] [-o option] [-x] [-d] filename</p>
    
    <p>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</p>
  </blockquote>
  
  <p>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. </p>
  
  <p>Does anyone have any insight into why this would be happening? Thanks in advance!</p>