Process() Print and Command Prompt

VanNiekerk

Newcomer
Joined
Oct 16, 2007
Messages
1
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:
C#:
//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:
Code:
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
 
Last edited by a moderator:
Not tried this personally but what happens if you just call the print.exe directly -
C#:
startinfo = new ProcessStartInfo();
startinfo.FileName = "print.exe";
startinfo.Arguments = "/D:" + printerName + " " + fileName + Convert.ToChar(13);

does that make a difference?
 
Back
Top