Edit
Attach
Printable
topic end
<!-- * Set TOPICTITLE = #define private public - Claus Brod on Windows (16 Jun 2009) --> <style type="text/css"> pre {background-color:#ffeecc;} </style> %STARTINCLUDE% <a name="16"></a> ---+++ [[DefinePrivatePublic20090616HeadUtilityOnWindows][<tt>head</tt> replacement on Windows]] (16 Jun 2009) <summary> A co-worker needed to convert a Cygwin-dependent script to something that runs on a bare-bones Windows system. The interesting part of the task was finding a replacement for the good ol' [[http://www.manpagez.com/man/1/head/][<tt>head</tt>]] command-line utility. </summary> Fortunately, this is fairly simple using a few lines of <nop>VBScript and the [[http://en.wikipedia.org/wiki/Windows_Script_Host][Windows Scripting Host]]. First, here's the <nop>VBScript code: <pre> lines = WScript.Arguments(0) Do Until WScript.stdin.AtEndOfStream Or lines=0 WScript.Echo WScript.stdin.ReadLine lines = lines-1 Loop </pre> This is an extremely stripped-down version of <tt>head</tt>'s original functionality, of course. For example, the code above can only read from standard input, and things like command-line argument validation and error handling are left as an exercise for the reader :D Assuming you'd save the above into a file called =head.vbs=, this is how you can display the first three lines of a text file called =someinputfile.txt=: <pre> type someinputfile.txt | cscript /nologo head.vbs 3 </pre> Enjoy! --- %STOPINCLUDE% %COMMENT{type="below" nonotify="on"}% ---
to top
End of topic
Skip to action links
|
Back to top
Edit
|
Attach image or document
|
Printable version
|
Raw text
|
Refresh
|
More topic actions
Revisions: | r1.2 |
>
|
r1.1
|
Total page history
|
Backlinks
You are here:
Blog
>
DefinePrivatePublic20090616HeadUtilityOnWindows
r1.2 - 19 Jun 2009 - 20:22 -
ClausBrod
to top
Blog
This site
2017
:
12
-
11
-
10
2016
:
10
-
7
-
3
2015
:
11
-
10
-
9
-
4
-
1
2014
:
5
2013
:
9
-
8
-
7
-
6
-
5
2012
:
2
-
10
2011
:
1
-
8
-
9
-
10
-
12
2010
:
11
-
10
-
9
-
4
2009
:
11
-
9
-
8
-
7
-
6
-
5
-
4
-
3
2008
:
5
-
4
-
3
-
1
2007:
12
-
8
-
7
-
6
-
5
-
4
-
3
-
1
2006:
4
-
3
-
2
-
1
2005:
12
-
6
-
5
-
4
2004:
12
-
11
-
10
C++
CoCreate Modeling
COM & .NET
Java
Mac
Lisp
OpenSource
Scripting
Windows
Stuff
Changes
Index
Search
Maintenance
Impressum
Datenschutzerklärung
Home
Webs
Atari
Blog
Claus
CoCreateModeling
Klassentreffen
Main
Sandbox
Sommelier
TWiki
Xplm
Jump:
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback