Using COM Ports for logging under Virtual PC / Virtual Server

Using COM Ports for logging under Virtual PC / Virtual Server

  • Comments 1

One interesting feature of Virtual PC / Virtual Server is the ability to map one of the virtual machines COM ports to a text file on the host computer.  This can be very handy for logging information on automated tests / batch jobs running inside of virtual machines.

Once you have configured your virtual machine to have its COM port point to a text file - you can write data to the text file from inside of the virtual machine quite easily.

Under DOS / Windows / OS/2 you can use the following commands:

  1. Echo "Hello World" > COM1

    Will put the contents of your string (in the case "Hello World") into your text file on the host.  A little trick to know is that 'Echo. > COM1' will insert a blank line into the text file.

  2. Type foo.txt > COM1

    Will copy the contents of a text file in the virtual machine (in this case 'foo.txt') to the text file on the host.

Under Linux the equivalent commands to use are:

  1. Echo "Hello World" > /dev/ttyS0


  2. Cat ./foo.txt > /dev/ttyS0

Note that under Linux, COM ports are 0 indexed (so ttyS0 = COM1, ttyS1 = COM2).  Also note that the Linux /dev/ttyS0 is case sensitive (the S is uppercase).


Leave a Comment
  • Please add 5 and 4 and type the answer here:
  • Post
  • In testing a program that will communicate with an external device over a serial link, it would be nice to put the program in a guest machine and have the virtual COM1 read from one real file but write to a different real file.

    That result can be accomplished by connecting the virtual COM1 to a named pipe and writing a separate program to run on the real machine, but it would be nice if this weren't necessary.
Page 1 of 1 (1 items)