Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

printing a file on a serial printer in a batchfile (win98se)

679 views
Skip to first unread message

Eduard Witteveen

unread,
Mar 12, 2004, 8:09:34 AM3/12/04
to
Hello,

I have a printer on my serial port (com1:) and a file that i want to print.

I can print this file by using the following commands:
MODE LPT1: = COM2:
MODE COM2: 9600,N,8,1,P
COPY filetoprint.txt LPT1


But when i try this in a batchfile, i get the error "Kan het pad niet
vinden. - lpt1" (translated: could not find path: lpt1)
@ECHO ON
MODE LPT1: = COM2:
MODE COM2: 9600,N,8,1,P
COPY %1 LPT1

The error occurs on the last line. Im sure that %1 has the proper
filename (i also replaced it with the filename).

The operating system i use is Windows 98 SE.

Could someone help me / give me some pointers?

ma...@toad-net.com

unread,
Mar 12, 2004, 12:45:10 PM3/12/04
to

I have never used a serial printer. But I have sent text strings through
a com port using:

type file > com#

Try it.

Ed Siff

unread,
Mar 12, 2004, 1:33:43 PM3/12/04
to
Unless the file you want to print is in the same folder as the batch file, you
have to specify the full path to it:

COPY drive:\foldername\filetoprint.txt LPT1

Ed

In article <4051b659$0$65160$d525...@news.wanadoo.nl>, Eduard Witteveen

Eduard Witteveen

unread,
Mar 12, 2004, 6:46:51 PM3/12/04
to
Ed Siff wrote:
> Unless the file you want to print is in the same folder as the batch file, you
> have to specify the full path to it:
>
> COPY drive:\foldername\filetoprint.txt LPT1
i dont get an error on the source, but on the destination. When i type
*exactly* the same on the commandprompt, it works. (in fact i simplified
the code, and it was an absolute path ;) )

foxidrive

unread,
Mar 12, 2004, 9:56:47 PM3/12/04
to
On Fri, 12 Mar 2004 14:09:34 +0100, Eduard Witteveen wrote:

> I have a printer on my serial port (com1:) and a file that i want to print.
>
> I can print this file by using the following commands:
> MODE LPT1: = COM2:
> MODE COM2: 9600,N,8,1,P
> COPY filetoprint.txt LPT1
>

> The operating system i use is Windows 98 SE.

I can't test it either, but will either of these work?
Is your printer is on COM2 or COM1?

@ECHO ON
MODE LPT1: = COM2:
MODE COM2: 9600,N,8,1,P

COPY "%1" LPT1:

@ECHO ON
MODE COM2: 9600,N,8,1,P
COPY "%1" COM2:

Eduard Witteveen

unread,
Mar 15, 2004, 3:15:47 AM3/15/04
to
ma...@toad-net.com wrote:
> I have never used a serial printer. But I have sent text strings through
> a com port using:
>
> type file > com#
>
> Try it.
I get the following error: "File creation error"
When i do an "type filename.txt > com1"

When i type this same command on the commandline, it works

Eduard Witteveen

unread,
Mar 15, 2004, 3:25:49 AM3/15/04
to
> @ECHO ON
> MODE LPT1: = COM2:
> MODE COM2: 9600,N,8,1,P
> COPY "%1" LPT1:
Batchfile: Path not found - LPT1
Commandline works (1 file copied)

>
> @ECHO ON
> MODE COM2: 9600,N,8,1,P
> COPY "%1" COM2:

Batchfile: Path not found - COM1
Commandline: works (1 file copied)

Im starting this batchfile from my application. Could this be related to
the problems im facing?

foxidrive

unread,
Mar 15, 2004, 3:31:44 AM3/15/04
to

Which application? Have you tried the batch files on their own, to test if
they work?

I did note that your batch files all use com2 but your error message states
com1... IIRC your initial msg stated your printer was on com1.

Eduard Witteveen

unread,
Mar 15, 2004, 4:04:15 AM3/15/04
to
> Which application? Have you tried the batch files on their own, to test if
> they work?
An Visual Basic 6 application, i start the batchfile by doing a api call
to the winexe
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/winexec.asp)

I tried the batchfile on it's own and it still gives me the same error
message. Can it have to do with the fact that copy and type are commands
defined in the command.com? :S

> I did note that your batch files all use com2 but your error message states
> com1... IIRC your initial msg stated your printer was on com1.

It is com1 on my computer, and com2 on the computer of the customer. I
messed up a little bit :D.

foxidrive

unread,
Mar 15, 2004, 4:30:56 AM3/15/04
to
On Mon, 15 Mar 2004 10:04:15 +0100, Eduard Witteveen wrote:

>> Which application? Have you tried the batch files on their own, to test if
>> they work?
> An Visual Basic 6 application, i start the batchfile by doing a api call
> to the winexe
> (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/winexec.asp)
>
> I tried the batchfile on it's own and it still gives me the same error
> message.

If it doesn't work on it's own...

> Can it have to do with the fact that copy and type are commands
> defined in the command.com? :S

winexec would shell to command.com I suspect, and it should work ok if it
works under dos.


I'm going to clutch at straws here coz I find the symptoms strange and
don't have a serial printer here to test it with.

1) Are you using a linux/unix box or odd application to create the batch
files, so the line ends are not CRLF but something else?

2) Are you using notepad to create the batch files, instead of something
which isn't saving in plain ascii text?

Which OS are you using it on?

> It is com1 on my computer, and com2 on the computer of the customer.

Ahh, ok.

Eduard Witteveen

unread,
Mar 15, 2004, 5:09:28 AM3/15/04
to
foxidrive wrote:
> I'm going to clutch at straws here coz I find the symptoms strange and
> don't have a serial printer here to test it with.
It is also neccesary to test on a windows 98 machine, to reproduce the
error message.
IMHO: There has to be a difference between the command-prompt and the
batchfile enviourment.


>
> 1) Are you using a linux/unix box or odd application to create the batch
> files, so the line ends are not CRLF but something else?

nodepad has always worked for me, also i would see it in the output of
the batchfile, if this messed up. I retyped the complete batchfile in
notepad and in edit.

> 2) Are you using notepad to create the batch files, instead of something
> which isn't saving in plain ascii text?

...

> Which OS are you using it on?

Windows 98 Second Edition.

ps:

Maybe you can try yourselve:


MODE LPT1: = COM2:
MODE COM2: 9600,N,8,1,P

COPY c:\autoexec.bat LPT1:
in batchfile should give an error and when the 3 lines are entered on
the commandline they will not(it behaves the same without anything
connected to the com port).

foxidrive

unread,
Mar 15, 2004, 5:32:24 AM3/15/04
to
On Mon, 15 Mar 2004 11:09:28 +0100, Eduard Witteveen wrote:

>> Which OS are you using it on?
> Windows 98 Second Edition.

A batch file runs under command.com in Win9x/ME so it will always work the
same from the command line and batch file, barring environment variables
and doubled percent signs and some other oddities.



> Maybe you can try yourselve:
> MODE LPT1: = COM2:
> MODE COM2: 9600,N,8,1,P
> COPY c:\autoexec.bat LPT1:
> in batchfile should give an error and when the 3 lines are entered on
> the commandline they will not(it behaves the same without anything
> connected to the com port).

I cut and pasted those three lines into a.bat and executed it. These lines
are executed from the batch file, not the command prompt.

===[screen capture]===
Microsoft(R) Windows 98
(C)Copyright Microsoft Corp 1981-1999.

C:\Download>a

C:\Download> MODE LPT1: = COM2:

Resident portion of MODE loaded

LPT1: rerouted to COM2:

C:\Download> MODE COM2: 9600,N,8,1,P

COM2: 9600,n,8,1,p

C:\Download> COPY c:\autoexec.bat LPT1:
1 file(s) copied
===[/screen capture]===

I can't explain your symptoms... Was the notepad you used in Win9x or NT?
If under NT, I wonder if the batch file was in Unicode format?
Look at it in a hex viewer, just to be sure.

Eduard Witteveen

unread,
Mar 15, 2004, 5:58:04 AM3/15/04
to
foxidrive wrote:
> I can't explain your symptoms... Was the notepad you used in Win9x or NT?
> If under NT, I wonder if the batch file was in Unicode format?
> Look at it in a hex viewer, just to be sure.
Place your a.bat in "Program Files" and try again :D. Aint that funny?

So apperently the LPT1 cannot be found if your working directory is
different from c:\

Thank you very much for all your time!

foxidrive

unread,
Mar 15, 2004, 6:13:58 AM3/15/04
to
On Mon, 15 Mar 2004 11:58:04 +0100, Eduard Witteveen wrote:

> Place your a.bat in "Program Files" and try again :D. Aint that funny?
>
> So apperently the LPT1 cannot be found if your working directory is
> different from c:\
>
> Thank you very much for all your time!

You seem to have a work around, which is good, but it works for me.


Microsoft(R) Windows 98
(C)Copyright Microsoft Corp 1981-1999.

C:\Program Files>a

Resident portion of MODE loaded

LPT1: rerouted to COM2:

COM2: 9600,n,8,1,p
1 file(s) copied
C:\Program Files>

Eduard Witteveen

unread,
Mar 15, 2004, 7:36:13 AM3/15/04
to
foxidrive wrote:
> You seem to have a work around, which is good, but it works for me.
Strange that i have this behaviour here and at my customer, when i type
command in start > run

Microsoft(R) Windows 98
(C)Copyright Microsoft Corp 1981-1999.

C:\WINDOWS\Desktop>ver

Windows 98 [Version 4.10.2222]


C:\WINDOWS\Desktop>


In properties screen:
Microsoft Windows 98 Second Edition
4.10.2222 A

The Saint

unread,
Apr 28, 2004, 4:28:03 PM4/28/04
to
I'm trying to make the batch file described in Q272623 below to print
to a file instead of to printer. I edited it to read as follows:

@echo off
dir %1 /-p /o:gn > "%temp%\Listing.txt"
start /w notepad "%temp%\Listing.txt"
exit

but it does not close the MS-DOS box.

Any help is much appreciated.

Sorry for the long post.
===============================

This article was previously published under Q272623
SUMMARY
This article explains how to add the print directory feature, and how
to enable printing of the directory listing from within Windows
Explorer.
MORE INFORMATION
To add the print directory feature to Windows Explorer, follow these
steps:
Open Notepad, and then copy and paste the following text into Notepad:
@echo off
dir %1 /-p /o:gn > "%temp%\Listing"
start /w notepad /p "%temp%\Listing"
del "%temp%\Listing"
exit

Save the file as Prin.bat in the Windows directory, and then close
Notepad.
Start Windows Explorer, click Tools, and then click Folder Options.
Click the File Types tab, and then click File Folder.
Click Edit, and then click New.
In the Action box, type Print Directory Listing.
In Application used to perform action, click Prin.bat, and then click
OK.
Click OK, click Apply, and then click OK.
Open Windows Explorer, right-click the folder that you would like to
print a directory listing of, and then click Print Directory Listing.
The information in this article applies to:
Microsoft Windows 98


Microsoft Windows 98 Second Edition

Microsoft Windows Millennium Edition

--
http://www.vdare.com

Matthias Tacke

unread,
Apr 28, 2004, 4:40:23 PM4/28/04
to
The Saint wrote:

>I'm trying to make the batch file described in Q272623 below to print
>to a file instead of to printer. I edited it to read as follows:
>
>@echo off
>dir %1 /-p /o:gn > "%temp%\Listing.txt"
>start /w notepad "%temp%\Listing.txt"
>exit
>
>but it does not close the MS-DOS box.
>
>Any help is much appreciated.
>
>Sorry for the long post.

The /w instructs the shell to wait until the started program is finished,
so if you don't want to delete the temporary file (like the example)
simply omit this switch and the window should be closed imedeately.

HTH
--
Greetings
Matthias

The Saint

unread,
Apr 28, 2004, 5:02:59 PM4/28/04
to

It works!!

Thanks.

One last question. I've researched this before posting here and, I
believe, the /p switch is a pause. But what does the /-p switch do?
Can it be deleted from the above batch file?

Again, thanks. You've been most helpful.
--
http://www.vdare.com

Matthias Tacke

unread,
Apr 28, 2004, 5:26:27 PM4/28/04
to
The Saint wrote:
>One last question. I've researched this before posting here and, I
>believe, the /p switch is a pause. But what does the /-p switch do?
>Can it be deleted from the above batch file?
>
>Again, thanks. You've been most helpful.

You can set some dir switches to the environment variable dircmd.
To be shure the output is continuous you can override that possible
setting with /-p.

See dir /?

--
Greetings
Matthias

0 new messages