Ghostscript command to finish a print job in interactive mode? - ghostscript

I am trying to build a shell service that prints PDF documents using Ghostscript running under Windows. The service should run a simple command via stdin with the filename of a PDF document and use the same printer and its settings as a context.
By default, Ghostscript starts in interactive mode. The idea is to use the same Ghostscript process rather than to run gswin64c.exe on each request to the service. Only for developing and testing, the Microsoft XPS Document Writer is used to get the result in the desired XPS file, which name is selected manually. That is why I use the Ghostscript device mswinpr2. At production environment, there will be another printer.
The command to start the Ghostscript process is as follows:
gswin64c.exe -dFitPage -dNOSAFER -dNOPAUSE -q setup_xps.ps
The Ghostscript code of setup_xps.ps:
mark
/NoCancel true % don't show the cancel dialog
/OutputFile (%printer%Microsoft XPS Document Writer)
/PageSize [114.0 85.0]
(mswinpr2) finddevice % select the Windows device driver
putdeviceprops
setdevice
Such a setup is the only way to set OutputFile to %printer%Microsoft XPS Document Writer: gswin64c.exe v9.54 does not recognize it correctly when passing through the command line (as a result, mswinpr2 opens the standard print dialog to choose a printer).
Then, to print a PDF document: (test.pdf) run.
However, the print job is left in the enqueuing state after. And the showpage command just adds a blank page to the output XPS document. It is seen when updating the printer's job queue.
The question is what PostScript or Ghostscript command (or another language) should be used to finish this print job (which closes the output XPS file gracefully), leaving in the interactive mode of the running Ghostscript process to execute further print commands like (test_2.pdf) run, (test_3.pdf) run and so on.

Related

DOORS make console the interactive window

Is there any way to tell DOORS to use the current command prompt window as the interactive window when executing in batch mode?
For example, if I have hello.dxl which looks like
print("Hello world")
and Run.bat which looks like
"C:\Program Files\IBM\Rational\DOORS\9.6\bin\doors.exe" -u test -pass testPass -b hello.dxl -W
It currently opens a new window, prints "Hello World" and then closes the window (it closes it because of the -W). Is there any way to redirect this output to the command prompt window that was opened to run the batch file?
There is no console variant of doors.exe and as far as I know there is no possibility to give a sort of handle to a specific prompt window and use e.g. OLE Automation to print to this window, so, basically, no, it's not possible.
A workaround that we use for this requirement is to have a batch file which
generates the name to a temporary file ,
passes this file to DOORS as a parameter (using environment variables)
make DOORS/DXL cout to this file
after the DXL has finished, type the content of the temporary file in the calling batch and optionally delete it.
PS: according to https://www.ibm.com/mysupport/s/question/0D50z00006HIM4oCAH/doors-print-redirect-tutorial-for-print-cout-and-logfiles it apparently used to be possible to redirect STDOUT/STDERR to a specific file, but not in recent DOORS versions.

How to print .txt file containing esc/pos commands using command prompt in windows?

I am trying to print ESC/pos commands from the .txt file using windows command prompt.
Let me explain what I tried so far:
I have connected my Epson Tm-m30 printer. Using a virtual port driver I can print the .txt file using the following command:
print /d:COM1 'file path'
Now my question: as it is, ESC/pos printer needs to print the ESC/pos commands like a paper cut, barcode printing, etc. When I paste the ESC/pos commands in the .txt file, it is print as it is, not as ESC/pos commands.
I am trying to print The following ESC/pos commands:
\x1B\x40
\x1D(k\x0d\x00\x30\x50\x30TEST PRINT
\x1D(k\x03\x00\x30\x51\x
But while printing it is printing it looks like above, not as ESC commands.
How do I print ESC/pos commands using a .txt file?
There are no commands built into Windows by default, so the following options are possible.
Use the tools distributed by EPSON
Send Data Tool
Issuing Receipts with Barcodes
Use a free tool published by someone somewhere
Create your own with a script tool such as PowerShell
about_Special_Characters
Make your own with C++/C#/VB etc.
Regex.Unescape(String) Method
Regular Expression Language - Quick Reference
Create a file with binary data instead of text and copy it to COM1 with the copy /b command

Run Python program in background - hide from taskbar

I have a Python script which collects some data and sends it over to a database. Using py2exe and Inno Setup, I have been able to create an .exe for distribution and also put the program run automatically when the computer (WINDOWS) starts; but the issue is that the command prompt window shows on the screen and on the taskbar. I don't have anything to show in the command prompt window so how can I make it run in the background without it being shown in the taskbar??
Please help!!! It is also OK if it shows up only as a tray icon.
Try to rename your script file to *.pyw format. It able to execute your script in background mode without command prompt.
That format available from v1.5:
The Windows configuration adds a new main program, "pythonw", and registers a new extension, ".pyw" that invokes this. This is a standard Python interpreter that does not pop up a console window; handy for pure Tkinter applications. All output to the original stdout and stderr is lost; reading from the original stdin yields EOF.
Maybe is late, but you have to force the .exe to run in background using runhidden in Inno Setup:
[Run]
Filename: "{app}\program.exe"; Flags: postinstall runhidden
Instead, if you want to run a python script or batch then you can use pythonw (Winodws OS):
pythonw script.py/script.bat

How do I convert .doc files to .txt using LibreOffice from the command line?

I have a folder of .doc files I would like to convert to .txt format. How can I do that using LibreOffice's command line mode in Windows 7? The files are located in C:\Temp\Test.
Here is how I handled this task using Windows PowerShell
Note: before using LibreOffice from the command line you need to close all existing instances of Libreoffice. This means closing all GUI sessions of LibreOffice as well as inspecting TaskManager for soffice.exe or a LibreOffice process running the background.
One Item:
PS &("C:\Program Files (x86)\LibreOffice 4\program\soffice.exe") -headless -convert-to txt:Text -outdir C:\Temp C:\Temp\test\sample.doc
This created a file sample.txt in C:\Temp from the document sample.doc
Multiple Items:
foreach ($file in Get-ChildItem C:\Temp\test)
{
&("C:\Program Files (x86)\LibreOffice 4\program\soffice.exe") -headless -convert-to txt:Text -outdir C:\Temp C:\Temp\test\$file | Out-Null
}
This created a .txt file for every file in the folder C:\Temp\test
Again: Use task manager to ensure that a previous version of soffice.exe is not running. This means closing existing GUI versions of LibreOffice.
Explanation:
Here is the documentation regarding Starting LibreOffice Software With Parameters. This will explain the soffice.exe command executed above.
Headless mode starts the LibreOffice software without a GUI. What I refer to in the question as 'command line mode'.
-convert-to is an important parameter in this example. When using -convert-to you need to know what the output_filter_name is (Text in the example above). A reference for those names can be found here. The output_filter_name will be the name of the files in that list that have the suffix .xcu
For example, if I wanted to convert my .doc files to .pdf I would use the parameter -convert-to pdf:writer_pdf_Export (untested)
Here is a reference I used when answering this question.
For some reason .exe processes need to pipe to Out-Null to avoid overlapping one another. Go figure.
The solution above was close, but required some alteration on LibreOffice 4.2 / Linux:
soffice --headless --convert-to txt:Text /path_to/file_to_convert.odt
(I did it with odt, the example I followed used doc: http://ask.libreoffice.org/en/question/14130/how-do-i-install-filters-for-the-soffice-command/)
An additional and important thing to add to #kevinaskevin 's answer is - the workaround is:
From the devs via IRC:
LO's "user installation" (i.e., ~/config/libreoffice) isn't designed to be accessed simultaneously by multiple processes; so when one soffice.bin is already running for a specific user installation, additional soffice.bin just forward their cmd line args to the first one and terminate immediately again (i.e., they shouldn't "fail" in the sense of exiting with a non-zero exit value)
if you want an independent headless LO, you can start it with an own user installation, -env:UserInstallation=<file URL to dir>

command line tool text output

I have a small command line tool and after running it, I'd like to display the text output in a way that's easy for someone to copy/paste and save it or email it to someone else.
Copy/pasting from a command prompt is not done in the standard way, so I don't want people to have to copy/paste from there. Saving the file to disk is possible, but the folder where the tool is located may not have access rights so the user would have to configure the output file location (this may be too tricky for some users).
I was thinking of launching notepad with some text in it, generated from the command line tool. Is this possible? Any other suggestions?
You can use clip.
After you have clip, which can be downloaded from the link above, you use the pipe (|) command to copy the previously executed command's output to the clipboard.
The article gives you the full explanation, but here are the basics with examples:
dir /h | clip – Copy the help manual for DIR command to the clipboard
tracert www.labnol.org | clip – Trace the path from your computer to another website – the output is automatically copied to the clipboard and not displayed on the screen.
netstat | clip - Check if your computer is connecting to websites without your knowledge.
I think your command sould receive the destination e-mail as a parameter and then after executing, your command you can have simple script/.BAT file which e-mails your text output to the user using the standard Telnet SMTP commands, like explained for example in the following page:
"http://www.yuki-onna.co.uk/email/smtp.html".
You could add an option to your program that tells it to copy its own output to the clipboard using the clipboard API. Then the user could just paste it.
I like the clip suggestion, though.

Resources