Printing text files under Windows. Keith Vetter 2. 00. Today I wanted to print a simple text from within tcl. I thought it should be easy- -it is just exec notepad /p myfile. But to do it properly turned out to be quite difficult. I'll explain why, but the ultimate command you need to executes is this: exec c: /winnt/system. First off, you need to look in the registry and find the print command for text files. HKEY_CLASSES_ROOT\. HKEY_CLASSES_ROOT\\$app\\shell\\print\\command {}]. NB. pcmd => %System. Root%\system. 32\NOTEPAD. EXE /p %1. Now put our file name for %1. IDM PowerTips Large file text editor. UltraEdit's file handling is designed to prevent it from using all the available memory, which would stop other applications. [Peter Newman 21 March 2004: The simplest way to print a text file on Windows is to go:-type d:\path\to\myfile.txt > prn. from the DOS prompt. 'Type' prints the. Edit Boot.ini in Windows or MS-DOS. Last reviewed: March 2005. On this page: About Boot.ini; About Editing Boot.ini; Backup Boot.ini How to edit Boot.ini if your. I am making a.bat file, and I would like it to write ASCII art into a text file. I was able to find the command to append a new line to the file when echoing text. NB. pcmd => %System. Root%\system. 32\NOTEPAD. EXE /p c: /temp/myfile. So far so good, but now when I try to execute it there are two problems. First, the %System. Root% needs to be handled, and second, the notepad window flashes momentarily. Windows 7 is the latest release of the Microsoft Windows family of operating systems for PCs, notebooks, netbooks, tablets and PC based media centers.Luckily, both problems can be handled by simply using start /min to run the command. WRONG - - this needs to be broken into words with eval. WRONG - - the backslashes in $pcmd are doubly interpreted. YEAH! (and don't try replacing the backslashes with forward slashes or 4. DOS/4. NT won't work)Putting it all together, here's a short procedure to print a text file on windows (w/ no error checking and tested only on Win. Print. Text {fname} {. HKEY_CLASSES_ROOT\. HKEY_CLASSES_ROOT\\$app\\shell\\print\\command {}]. ![]() This will not work on W2k, if pcmd contains spaces, and is quoted with "", as start will interpret it as the window title. Win. 9x). Adding a "" to the command line helps. KPV could you explain your fix more. Or perhaps you could insert a dummy window title. HZe I have had similar problems with the command start and the usage of quotes "". The most robust solution I found is to convert all filenames to Windows shortnames by set filename [file attribute $filename - shortname]and don't include it in quotes. Otherwise I didn't get it to work on Windows NT, 2. XP. schlenk I did check for NT and Win. W2k and up which do that and simply insert a dummy value if needed. Its braindead but documented in the help file of the start command.. See also: Tcl 9. 0 Wish. List - #6. 6. AMkroc informed me about yet another utility that is available for this type of things: [1]. Typical usage. [catch [ list exec printraw. KPV But the whole point of the above exercise was to ask the Windows OS how to print a text file. Theorectically it should work regardless of which utility is present or not. AM I just (mis)used the page to document this utility - I could not find the other one. A text file (sometimes spelled 'textfile': an old alternative name is 'flatfile') is a kind of computer file that is structured as a sequence of lines of electronic text. Edit examples. edit c:\autoexec.bat. This would look at the autoexec.bat. However, if the file is not found a blank blue screen is shown. When editing this or any. I quite appreciate this insight, as I have an immediate use for it!! AM Can anyone shed light on the question how to achieve this on a Macintosh? I do not have access to one, but I am interested to know how it would work there)Lars H In Mac OS X there is a Unixy command enscript which can be used for this. Probably the traditional lp/lpr can be used as well (although these may in fact be using the enscript thing to do formatting and such). On Mac OS 9 you would probably have to do something along the lines above: starting "Simple. Text" (or whatever it is called in English), tell it to open a new file, tell it to insert the text you want, and then tell it to print the thing; all via Apple. Events directly (e. Tcl. AE) or via Applescript (the Tclapplescript extension). If the text is already in a file it might however be easier to tell the Finder to print it, as that will then call upon the proper application to do the printing. Also, check out http: //sf. Tcl/Tk library and program to allow easy printing to the Nintendo Gameboy Printer from a PC.[Peter Newman 2. March 2. 00. 4: The simplest way to print a text file on Windows is to go: - type d: \path\to\myfile. DOS prompt. "Type" prints the specified file to stdout (by default). It's the DOS equivalent to Unix's CAT. The "> prn" re- directs output to the default printer. So from Tcl: - exec $env(COMSPEC) /c type [file attribute d: \path\to\myfile. ![]() ![]() ALL versions of DOS and Windows. COMSPEC is an environment variable that I understand is available on all versions of Windows and points to the DOS shell (typically either COMMAND. COM or CMD. EXE). And we convert the file to 8. DOS systems that don't support long filenames. Unfortunately, the above doesn't work. Exec complains: - Can't execute "c: \windows\command. But c: \windows\command. COMSPEC) evaluates to on my system) DOES exist. So either I've wired up the call to exec wrong - or exec has a bug in it. I couldn't be bothered trying to figure exec out (as you can see from all the ifs, but and maybes in the man page - and from the discussion above, that command is a bug- ridden disaster that needs a LOT more work). Use winutils launch or shell instead, and it'll work. EKB It worked for me! Tcl 8. 4. 7. 0 didn't complain about a nonexistent COMSPEC when I ran something like the above code. The difference between the "notepad /p myfile. CPI ASCII mode. It by- passes the Windows printer driver. So it's fast (printing starts immediately). But the font is quite large - so you waste lots of paper. The "notepad /p myfile. Windows printer driver. So there's a 3 year delay before printing starts - but the font used is usually smaller. Hence less wasted paper. KPV On my Win. 2k with a local Canon printer this doesn't work- -the command returns immediately but comes out on the printer. Also, I have my doubts on how this would work with a network printer. Peter Newman 2. 1 March 2. Yeah! The point I was trying to make was that the STANDARD way to print a text file from DOS/Windows is to go: - type d: \path\to\myfile. DOS prompt. I know that works on any version of DOS (from 2. Windows 9. 5/9. 8 (because I've done it a million times). I ASSUME it'll also work on Windows 2. NT and XP. But maybe not. Did you try typing the above from the DOS prompt? It also works just fine with Perl's system command (on DOS and Windows 9. But it doesn't work with Tcl's exec. The problem is with exec (and/or the way we're calling it). Use winutils instead. It should work with network printers too. But they have to be set up right. Usually PRN points to the DOS/Windows default printer. And LPT1 is a synonym for PRN. And LPT2 to LPT4 point to any other printers you may have. But you'll have to check your DOS/Windows documentation for the details - especially how configure them to point to your network printers. I've never myself tried this with network printers - though I'm sure it can be done. KPV Sorry, I was unclear: the command fails for me even from the command prompt. Win. 95/9. 8 are radically different than win. XP- -they're really just a shell on top of command. I'm NOT surprised it doesn't work. Peter Newman: If in doubt, read the manual I went to the Microsoft web site and looked at the Win. And sure enough it has a TYPE command. But that command DOESN'T support re- direction to printers. Instead, there's PRINT command for printing text files to printers. And that PRINT command supports both local and network printers. So to summarise! To print a text file under DOS/Windows from the DOS prompt (and assuming that Win 2. K, NT and XP all work the same): - type d: \path\to\myfile. DOS and Windows 9x. Win 2. K (and presumably also NT and XP)And since anything you can do from the DOS prompt, you should also be able to do with exec, you should also be able to do those from Tcl. Also, I don't think it's true that Win 2. K, NT and XP are radically different from DOS and Win 9x. Win 2. K, NT and XP support basically the same DOS commands as Win 9x. But there are some minor differences - as with TYPE/PRINT described above. And there are a whole load of new network/Internet related commands - to give the Win 2. K, NT and XP command prompt a lot more Unix like power. KPV The difference between Win. Win. NT/2. K/XP is that the former uses DOS as it's underlying OS while the latter is a totally new OS written from scratch. Peter Newman Not as far as the DOS Prompt and printing text files is concerned. The Win 2. K/NT/XP DOS Prompt is a straight- forward upgrade of the Win 9x/DOS DOS Prompt. The traditional DOS commands are all there - with exactly the same syntax (ok, maybe a few small differences) - and lots of enhancements. Note also that: -Under DOS and Windows 9x you can also use: - COPY /b d: \path\to\myfile. The PRINT differs from TYPE and COPY is that it maintains a background print spooler. So it's slower. The printer support in TYPE and COPY (under DOS and Windows 9x) stems from the days where printers where connected to the PARALLEL port. Nowadays, most printers are USB or network connected. So even under DOS and Windows 9x, you won't be able to TYPE or COPY to a USB or network printer unless the OS concerned supports them. PRINT is also available under Windows 9x and DOS. I've got a DOS version 4. Looking on the Internet I found references to the fact that Win 2. K, NT and XP have a 1. Apparently it can be fixed - and Microsoft have details on how to do this. So to SUMMARISE (again)! To print a text file under DOS/Windows: -. Go to your DOS Prompt Reference Manual and check out the: - commands. Then use whichever works (on your system). But note that: -The alternative method of using "NOTEPAD /P" (discussed above), has the advantage of using smaller font sizes. So it usually looks better - and wastes less paper. COPY, TYPE and PRINT generally wrap long lines automatically. So they're usually the best solution for PROGRAM LISTINGS. NOTEPAD usually silently truncates long lines (which is irritating/dangerous with program listings). NOTEPAD (at least the Windows 9. Unix and Mac text files. It usually sees them as one long line. A major PITA. It may be the same with COPY, TYPE and PRINT. Whether the later versions of Windows are more Unix/Mac friendly I don't know. So you may have line ending translation issues to worry about too. Note by Pi. Pa, march 2. Word. 20. 00, add a space in any position, optionally delete that space, save the file as . Done. All LF alone are converted in CRLF)Another Windows text file printing option to check, is winutils: :shellwinutils.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
October 2016
Categories |