VanNiekerk Posted October 18, 2007 Posted October 18, 2007 (edited) Please please can some one help me out here...this is making me so frustrated! I have a text file which I write some data to. I then print this text file in my c# class using the System.Diagnostics.Process() method. My code looks like this: //set the command to run via the cmd prompt command = "print /D:" + printerName + " " + fileName + Convert.ToChar(13); startinfo = new ProcessStartInfo(); // use command prompt startinfo.FileName = "cmd.exe"; // /c switch sends a command startinfo.Arguments = "/C " + command; // don't exec with shellexecute api startinfo.UseShellExecute = false; // redirect stdout to this program startinfo.RedirectStandardOutput = true; // don't open a cmd prompt window startinfo.CreateNoWindow = false; // start cmd prompt, execute command myProcess = Process.Start(startinfo); myProcess.WaitForExit(1500); // retrieve stdout line by line stdoutreader = myProcess.StandardOutput; while ((stdoutline = stdoutreader.ReadLine()) != null) { consoleoutput = consoleoutput.Insert(consoleoutput.Length, " => " + stdoutline); } stdoutreader.Close(); stdoutreader = null; It works great on my local machine. I have now moved it to the test server and have come across this issue. It has confused me and any assistance would be greatly received! I can execute the following in the command prompt on the server: print /D:\\wsrp001prt.rph.au\psrpists09 E:\websites\rp\Oral\Print\Referral1.txt and I get the message: E:\websites\rp\Oral\Print\ReferralPatient1.txt is currently being printed However I execute the same line in my project using the code stated above and get the output of: Unable to initialize device \\wsrp001prt.rph.au\prrpists09 Why the difference? Both load up the command prompt and execute the same code but have different outputs. Why and how do I go about fixing this? Any help or ideas? Many thanks Tracey Edited October 18, 2007 by PlausiblyDamp Quote
Administrators PlausiblyDamp Posted October 18, 2007 Administrators Posted October 18, 2007 Not tried this personally but what happens if you just call the print.exe directly - startinfo = new ProcessStartInfo(); startinfo.FileName = "print.exe"; startinfo.Arguments = "/D:" + printerName + " " + fileName + Convert.ToChar(13); does that make a difference? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.