0

I have tried this command on cmd.

lpr -S 127.0.0.1 -P testP -J testJ D:\output\test.txt >> d:\result.txt

it's worked and result wrote in "d:\result.txt"

Error: could not open D:\output\test.txt for reading.

But when run lpr command via ProcessStartInfo

int exitCode;
ProcessStartInfo processInfo;
Process process;
var cmdcommand = @"lpr -S 127.0.0.1 -P testP -J testJ D:\output\test.txt >> d:\result.txt";

processInfo = new ProcessStartInfo(@"cmd.exe", "/c " + cmdcommand);
processInfo.CreateNoWindow = false;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardOutput = true;
processInfo.RedirectStandardError = true;

process = new Process();
process.StartInfo = processInfo;
process.Start();
process.WaitForExit();
string texterror = process.StandardError.ReadToEnd();
string textoutput = process.StandardOutput.ReadToEnd();
exitCode = process.ExitCode;
process.Close();

No error showed in "d:\result.txt" I need to catch some errors result via code. Thank you in advanced

PS. I've used Windows 10 64 bit and Fixed lpr cannot run by use Joe G solution from here C# - LPR Command to Print PDF Files

PS2. Sorry for grammar error.

0 Answers0