• Quick note - the problem with Youtube videos not embedding on the forum appears to have been fixed, thanks to ZiprHead. If you do still see problems let me know.

Windows command line stuff

Rat

Not bored. Never bored.,
Joined
May 19, 2003
Messages
10,629
Location
Leicester, UK
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.
 
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
 
Last edited:
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 

Back
Top Bottom