View Full Version : Windows command line stuff
Rat
22nd August 2007, 09:24 AM
It's embarrassing to have to ask such a basic question, but it is literally years since I did anything meaningful at the Windows command line, and I've forgotten a lot of even the most basic stuff.
What I want is to be able to run a command in a batch file, send selected parts of its output to file, and then open the text file. To pick an example, let's say I want the host name of the machine running the batch file (I realize there are easier ways to get this, but bear with me). So the batch file could call "ipconfig /all", for example, to get the host name. How can I then write the single line containing this information to file? If I want to pick several different lines from several different commands' outputs, how do I output them all to the same file, appending each after the last?
Any pointers would be appreciated.
roger
22nd August 2007, 09:31 AM
ipconfig /all > out.txt
Creates a file called out.txt containing the output of the command.
To append, you can do something like
dir >> out.txt
will append the results of dir to the file out.txt
find "Host Name" out.txt >> results.txt
This will find the Host Name of your computer in the ipconfig file, and copy it to results.txt.
You can make a batch file of a string of these commands, compiling the results into a text file, then delete the intermediate files.
However, for what you are specifically doing, I think using the pipe command to pass the results from one operation into another is what you want to do:
ipconfig /all | find "Host Name" >> results.txt
will run ipconfig, pass the output to the find command, which will display all lines containing "Host Name", and append it to the file results.txt
Rat
22nd August 2007, 10:03 AM
That's absolutely perfect. Thanks. I knew it was something to do with piping (hence the tag), but couldn't remember what that involved. I'll have a play with that.
Wudang
22nd August 2007, 12:41 PM
Have a look at something like windows scripting (from MS) or perl.
http://www.microsoft.com/technet/scriptcenter/default.mspx
www.perl.org
Friends don't let friends do dos commands
Rat
22nd August 2007, 12:58 PM
Hmm, I did start learning Windows scripting a couple of years ago, and I'd like to do what I'm trying to do in that form. But a couple of things I intend to do are things that I want to bung in the domain logon batch file, so I thought it'd be easier to do it that way.
negativ
22nd August 2007, 04:06 PM
I haven't played around with this very much yet, but it looks interesting:
http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx
ETA:
Bah! That will teach me to read a thread before replying to the OP.
Actually, it won't, but I like to pretend it will.
Paul C. Anagnostopoulos
26th August 2007, 06:38 PM
Have a look at something like windows scripting (from MS) or perl.
...
Friends don't let friends do dos commands,
With friends like you recommending Perl, who needs enemies? :D
Forget the stupid Windows DOS box and get 4NT:
http://www.jpsoft.com/4ntdes.htm
~~ Paul
Disclaimer: I wrote this book: http://www.amazon.com/Writing-Real-Programs-DCL-Technologies/dp/1555581919/ref=sr_1_1/103-6071629-2815007?ie=UTF8&s=books&qid=1188175069&sr=8-1. Infer from that what you will.
Wudang
27th August 2007, 05:56 PM
4NT is $75 from that link.
I wrote a chapter of this book http://publib.boulder.ibm.com/infocenter/cicsts/v3r1/index.jsp
infer fro.....
Okay I'll get me coat
Paul C. Anagnostopoulos
27th August 2007, 08:03 PM
4NT is $75 from that link.
And a bargain at twice the price.
I wrote a chapter of this book
Ooh, software for z/OS?
~~ Paul
Wudang
28th August 2007, 12:57 PM
Yes. I worked to work at IBM's Hursley lab and was one of the few who really understood IBM's RACF security product so I was asked to write a chapter on settng up security.
Paul C. Anagnostopoulos
28th August 2007, 01:38 PM
Cool, Wudang!
~~ Paul
Wudang
29th August 2007, 04:44 PM
It's not often people describe z/OS as cool.
To be honest, I have a few years experience on Unix and windows but I still think MVS may not be the prettiest or most orthogonal but if you have lots of data that needs shifting between disk and memory, MVS and its z/OS descendants is what you need.
Paul C. Anagnostopoulos
29th August 2007, 04:51 PM
I spent four years computing on a 360/67 running CP/CMS. Now that was cool.
~~ Paul
Wudang
29th August 2007, 05:10 PM
Yeah! As a trainee sysprog in 1984 onwards and single etc I used to stay playing until 4 am on a 4381 which I had all to myself. My married colleagues would go home to play with their sinclairs etc while I was getting to grips with MODESET and SVC 34 etc.
I still monitor www.cbttape.org even though most of my coding these days is java and perl on unix.
Paul C. Anagnostopoulos
29th August 2007, 06:29 PM
You know about bitsavers, too, I presume?
http://www.bitsavers.org/
~~ Paul
Wudang
30th August 2007, 06:01 AM
Yeah - never found anything I really wanted on there though for some reason. Seems like a site I'd have to trawl with lots of spare time whereas I'm usually looking for something pretty specific - data flows for APPC traffic etc.
Paul C. Anagnostopoulos
30th August 2007, 08:00 AM
I think everything at the site is fascinating. But then, I've been around a bit too long.
~~ Paul
Wudang
30th August 2007, 02:08 PM
I probably would have a few years back but one of the advantages of having been a sys prog/software engineer with IBM for 15 years was that I had access to the internal forums where the guy who designed a chip or coded the SLIH would be participating and I got spoilt.
Now I work for a bank integrating monitoring systems and have a 2 year old, my concerns are much more immediate. Though I did still buy Carmine Canatello's Advanced Assembler when I found out about it.
© 2001-2009, James Randi Educational Foundation. All Rights Reserved.
vBulletin® v3.7.7, Copyright ©2000-2012, Jelsoft Enterprises Ltd.