Linked by Thom Holwerda on Thu 10th Jun 2010 12:53 UTC
Thread beginning with comment 429513
To read all comments associated with this story, please click here.
To read all comments associated with this story, please click here.
RE: You can solve anything with a little code
by sorpigal on Thu 10th Jun 2010 20:40
in reply to "You can solve anything with a little code"




Member since:
2006-08-01
Here Thom, I have a present for you. True, it's a dirty hack that I threw together just now but it does provide some basic functionality. Basically, create the directory C:\Queue and share it. then run the following VB.NET hack on your system. Whenever you print in Linux you can just print to file and save the .PDF output to the share \\yourserver\queue and the program will send it to the default printer. there are many limitations but I'm sure it could be cleaned up:
Imports System.Diagnostics
Imports System.IO
Module modBasicQueue
Sub Main()
'******************************Written by Matt Paulauskas*********************************
'****************************************2010************************ *********************
Const qd = "C:\Queue\"
Console.WriteLine("Waiting for file to print")
Do '//continuous file check/print/delete loop
If Directory.GetFiles(qd).Count > 0 Then '//Check for files...if found send to printer and delete
For Each qFile As String In Directory.GetFiles(qd) '// iterate through files
Try
Dim psi As New ProcessStartInfo
With psi
.Verb = "print"
.WindowStyle = ProcessWindowStyle.Hidden
.FileName = qFile
.UseShellExecute = True
.Arguments = "/silent"
End With
'// Display file being printed
Console.WriteLine("Printing: " & qFile)
Dim proc As New Process
proc.StartInfo = psi
proc.Start()
Threading.Thread.Sleep(500)
TryAgain:
'//clean up after file has been printed
Try
File.Delete(qFile)
Catch ex As Exception
'//file was probably locked by the app resonsible for printing it
'//Sleep the thread for 20ms and try again
Threading.Thread.Sleep(20)
GoTo TryAgain
End Try
'//Clean up running process
Try
proc.Kill()
Catch ex As Exception
End Try
Catch ex As Exception
Console.WriteLine("Print Operation: " & ex.Message)
End Try
Next
End If '//end file check
Threading.Thread.Sleep(1000) '//pause before next check
Loop
End Sub
End Module