Darshan Kshirasagar

Darshan Kshirasagar

  • NA
  • 317
  • 67.1k

When Execute Print cmd error Unable to initialize device PRN

Mar 26 2019 12:33 AM
Hi,
 
Using Command Prompt tried cmd "Print D:\PrintTest.txt"  its worked proper, But the same command i am executing like below code through program it error "Unable to initialize device PRN" can anyone tell me the Issue why error ..?
  1. private string ExecuteCMD(List ListCmd)  
  2. {  
  3. try  
  4. {  
  5. string result;  
  6. using (Process cmd = new Process())  
  7. {  
  8. cmd.StartInfo.FileName = "cmd.exe";  
  9. cmd.StartInfo.RedirectStandardInput = true;  
  10. cmd.StartInfo.RedirectStandardOutput = true;  
  11. cmd.StartInfo.RedirectStandardError = true;  
  12. cmd.StartInfo.CreateNoWindow = true;  
  13. cmd.StartInfo.UseShellExecute = false;  
  14. cmd.Start();  
  15. foreach (var sdata in ListCmd)  
  16. {  
  17. cmd.StandardInput.WriteLine(sdata);  
  18. }  
  19. cmd.StandardInput.Flush();  
  20. cmd.StandardInput.Close();  
  21. result = cmd.StandardOutput.ReadToEnd();  
  22. cmd.WaitForExit();  
  23. cmd.Close();  
  24. }  
  25. return result;  
  26. }  
  27. catch (Exception ex)  
  28. {  
  29. MessageBox.Show("Error Occured " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
  30. }  
  31. return "";  
  32. }  
  33. private void PrintData()  
  34. {  
  35. try  
  36. {  
  37. List objList = new List();  
  38. objList.Add(@"cd /d " + "D:/");  
  39. objList.Add(@"Print D:\PrintTest.txt");  
  40. textBox1.Text = ExecuteCMD(objList);  
  41. }  
  42. catch (Exception ex)  
  43. {  
  44. MessageBox.Show("Error Occured " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
  45. }  
  46. }