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 ..?
- private string ExecuteCMD(List ListCmd)
- {
- try
- {
- string result;
- using (Process cmd = new Process())
- {
- cmd.StartInfo.FileName = "cmd.exe";
- cmd.StartInfo.RedirectStandardInput = true;
- cmd.StartInfo.RedirectStandardOutput = true;
- cmd.StartInfo.RedirectStandardError = true;
- cmd.StartInfo.CreateNoWindow = true;
- cmd.StartInfo.UseShellExecute = false;
- cmd.Start();
- foreach (var sdata in ListCmd)
- {
- cmd.StandardInput.WriteLine(sdata);
- }
- cmd.StandardInput.Flush();
- cmd.StandardInput.Close();
- result = cmd.StandardOutput.ReadToEnd();
- cmd.WaitForExit();
- cmd.Close();
- }
- return result;
- }
- catch (Exception ex)
- {
- MessageBox.Show("Error Occured " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- return "";
- }
- private void PrintData()
- {
- try
- {
- List objList = new List();
- objList.Add(@"cd /d " + "D:/");
- objList.Add(@"Print D:\PrintTest.txt");
- textBox1.Text = ExecuteCMD(objList);
- }
- catch (Exception ex)
- {
- MessageBox.Show("Error Occured " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }