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:
- 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.
- 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:
- Echo “Hello World” > /dev/ttyS0
- 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).