Jul 2, 2013 - Under Linux there are serial devices, redirection and netcat for that. Like this, for example https://www.eltima.com/serial-port-redirector/. Virtual serial port. One variant of a COM port redirector is a virtual serial port. A virtual serial port is a redirector without network software support which is usually used to create a pair of back-to-back virtual COM ports on the same computer.
Features | Documentation | Knowledge Base | Discussion Forums
The following sections describe how to use serial ports with VMware Workstation:
A VMware Workstation virtual machine can use up to four virtual serial ports. The virtual serial ports can be configured in several ways.
- You can connect a virtual serial port to a physical serial port on the host computer.
- You can connect a virtual serial port to a file on the host computer.
- You can make a direct connection between two virtual machines or between a virtual machine and an application running on the host computer.
You can also select whether to connect the virtual serial port when you power on the virtual machine.
Note: The serial port implementation is new in this release and deprecates the use of TTY type of virtual serial ports in a virtual machine.
You can set up the virtual serial port in a virtual machine to use a physical serial port on the host computer. This is useful, for example, if you want to use an external modem or a hand-held device in your virtual machine.
To install a virtual serial port that connects to a physical serial port on the host computer, take the following steps:
- Open the Configuration Editor (Settings > Configuration Editor).
- Click Add to start the Add Hardware Wizard.
- Select Serial Port, then click Next.
- Select Use Physical Serial Port, then choose the port on the host computer that you want to use for this serial connection.
- Click Finish, then click OK to close the Configuration Editor.
- Power on the virtual machine.
- Open the Configuration Editor (Settings > Configuration Editor).
- Select one of the virtual serial ports (COM1 through COM4).
- Choose a type of Device from the pull-down menu.
- In the Path field, enter the path to the device you want to connect to the virtual serial port, for example, /dev/ttyS0 to use the first physical serial port on the host computer.
- Click Install.
- Click OK to save your configuration and close the Configuration Editor.
- Power on the virtual machine.
You can set up the virtual serial port in a virtual machine to send its output to a file on the host computer. This is useful, for example, if you want to capture the data a program running in the virtual machine sends to the virtual serial port or if you need a quick way to transfer a file from the guest to the host.
To install a virtual serial port that connects to a file on the host computer, take the following steps:
- Open the Configuration Editor (Settings > Configuration Editor).
- Click Add to start the Add Hardware Wizard.
- Select Serial Port, then click Next.
- Select Use output file and browse to the file on the host computer that you want to use to store the output of the virtual serial port.
- Click Finish, then click OK to close the Configuration Editor.
- Power on the virtual machine.
- Open the Configuration Editor (Settings > Configuration Editor).
- Select one of the virtual serial ports (COM1 through COM4).
- Choose a type of File from the pull-down menu.
- In the Path field, enter the path to the file on the host computer that you want to use to store the output of the virtual serial port.
- Click Install.
- Click OK to save your configuration and close the Configuration Editor.
- Power on the virtual machine.
You can set up the virtual serial port in a virtual machine to connect to an application on the host computer. This is useful, for example, if you want to use an application on the host to capture debugging information sent from the virtual machine's serial port.
To install a direct serial connection between an application on the host and a virtual machine, take the following steps:
- Open the Configuration Editor (Settings > Configuration Editor).
- Click Add to start the Add Hardware Wizard.
- Select Serial Port, then click Next.
- Select Use named pipe.
- Use the default pipe name, or enter another pipe name of your choice. The pipe name must follow the form .pipe<namedpipe> - that is, it must begin with .pipe.
- Select This end is the server or This end is the client. In general, select This end is the server if you plan to start this end of the connection first.
- Select The other end is an application.
- Click Finish, then click OK to close the Configuration Editor.
- On your host computer, configure the application that communicates with the virtual machine to use the same pipe name.
- Power on the virtual machine.
- Open the Configuration Editor (Settings > Configuration Editor).
- Select one of the virtual serial ports (COM1 through COM4).
- Choose a type of Pipe from the pull-down menu.
- In the Path field, enter /tmp/<socket> or another Unix socket name of your choice.
- Select Server or Client. In general, select Server if you plan to start this end of the connection first.
- Click Install.
- Click OK to save your configuration and close the Configuration Editor.
- On your host computer, configure the application that communicates with the virtual machine to use the same Unix socket name.
- Power on the virtual machine.
You can set up the virtual serial ports in two virtual machines to connect to each other. This is useful, for example, if you want to use an application in one virtual machine to capture debugging information sent from the other virtual machine's serial port.
To install a direct serial connection between two virtual machines (a server and a client), take the following steps:
- Open the Configuration Editor (Settings > Configuration Editor).
- Click Add to start the Add Hardware Wizard.
- Select Serial Port, then click Next.
- Select Use named pipe.
- Use the default pipe name, or enter another pipe name of your choice. The pipe name must follow the form .pipe<namedpipe> - that is, it must begin with .pipe.
- Select This end is the server.
- Select The other end is a virtual machine.
- Click Finish, then click OK to close the Configuration Editor.
- Open the Configuration Editor (Settings > Configuration Editor).
- Click Add to start the Add Hardware Wizard.
- Select Serial Port, then click Next.
- Select Use named pipe.
- Use the default name, or enter another pipe name of your choice. The pipe name must follow the form .pipe<namedpipe> - that is, it must begin with .pipe. The pipe name must be the same on server and client.
- Select This end is the client.
- Select The other end is a virtual machine.
- Click Finish, then click OK to close the Configuration Editor.
- Open the Configuration Editor (Settings > Configuration Editor).
- Select one of the virtual serial ports (COM1 through COM4).
- Choose a type of Pipe from the pull-down menu.
- In the Path field, enter /tmp/<socket> or your choice of Unix socket name.
- Select Server.
- Click Install.
- Click OK to save your configuration and close the Configuration Editor.
- Open the Configuration Editor (Settings > Configuration Editor).
- Select one of the virtual serial ports (COM1 through COM4).
- Choose a type of Pipe from the pull-down menu.
- In the Path field, enter /tmp/<socket> or another Unix socket name of your choice. The pipe name must be the same on server and client.
- Select Client.
- Click Install.
- Click OK to save your configuration and close the Configuration Editor.
![Redirection Redirection](http://www.serial-port-redirector.com/serial-port-redirector-help/img/products/spr/help/physical-server-settings.gif)
Two special configuration options are available for serial connections between a virtual machine and the host or between two virtual machines. These options are of interest primarily to developers who are using debugging tools that communicate over a serial connection.
The first option must be set in the Configuration Editor. It is useful when the serial port is being used by the guest operating system in polled mode as opposed to interrupt mode. Polled mode causes the virtual machine to consume a disproportionate share of CPU time. This makes the host and other guests run sluggishly.
To restore performance for applications on the host, in the Configuration Editor, select the virtual serial port, and check the Yield CPU on poll check box. This configuration option forces the affected virtual machine to yield processor time if the only thing it is trying to do is poll the virtual serial port.
The second option - serial<n>.pipe.charTimePercent = <x> - should be added as a new line to your virtual machine's configuration file. (Power off the virtual machine and close the VMware Workstation window before editing the configuration file.) It is useful to squeeze every possible bit of speed from your serial connection over a pipe to the virtual machine. There is no limit on the output speed, which is how fast the virtual machine sends data through the virtual serial port. The output speed depends on how fast the application at the other end of the pipe reads data inbound to it.
<n> is the number of the serial port, starting from 0. So the first serial port is serial0. <x> is any positive integer. It specifies the time taken to transmit a character, expressed as a percentage of the default speed set for the serial port in the guest operating system. For example, a setting of 200 forces the port to take twice as long per character, or send data at half the default speed. A setting of 50 forces the port to take only half as long per character, or send data at twice the default speed.
You should first use the guest operating system to configure the serial port for the highest setting supported by the application you are running in the virtual machine.
Once the serial port speed is set appropriately in the guest operating system, experiment with this setting. Start with a value of 100 and gradually decrease it until you find the highest speed at which your connection works reliably.
You can use Debugging Tools for Windows (WinDbg) or Kernel Debugger (KD) to debug kernel code in a virtual machine over a virtual serial port. You can download Debugging Tools for Windows from the Windows DDK Web site at www.microsoft.com/ddk.
The following two examples illustrate how to use a virtual serial port to debug kernel code in a virtual machine:
- Where the debugging application is on the VMware Workstation host (Windows hosts only)
- Where the debugging application is in another virtual machine on the same VMware Workstation host (which is useful on a Linux host, but can also be done on a Windows host)
Using either of these methods lets you debug kernel code on one system, without the need for two physical computers, a modem or serial cable.
In this situation, you have kernel code to debug in a virtual machine (called the target virtual machine) and are running WinDbg or KD on your Windows host.
To prepare the target virtual machine, follow the steps for a Windows host in Connecting an Application on the Host to a Virtual Machine. Make sure you configure the virtual machine's virtual serial port as follows:
- Select This end is the server
- Under I/O Mode, select the Yield CPU on poll check box, as the kernel in the target virtual machine uses the virtual serial port in polled mode, not interrupt mode
To prepare the host, make sure you have downloaded the correct version of Debugging Tools for Windows. You need version 4.0.18.0, dated December 21, 2001, as it supports debugging over a pipe.
Note: Pipe support is not documented in the WinDbg and KD in-product help or on Microsoft's Web site.
When you are ready to begin, complete the following steps:
- Power on the virtual machine.
- Check to make sure the serial port is connected. On the Devices menu, serial<n> should say Connecting, as it is waiting to connect to the host on the other end of the pipe. Note: If the serial<n> says (Not connected), then the serial port may not be connected. Choose the virtual serial port, then Connect.
- On the host, open a Command Prompt window and do one of the following:
- If you are using WinDbg, type the following:
- If you are using KD, type the following:
kd -k com:port=.pipe<namedpipe>,pipe
Then press Enter to start debugging.
In this situation, you have kernel code to debug in a virtual machine (called the target virtual machine) and are running Debugging Tools for Windows (WinDbg) or Kernel Debugger (KD) in another virtual machine (called the debugger virtual machine) on the same host.
This is useful if you are running VMware Workstation on a Linux host. The debugger virtual machine must be running Debugging Tools for Windows (WinDbg) or Kernel Debugger (KD) in a Windows guest operating system.
To prepare the target virtual machine, follow the steps for the server virtual machine for the appropriate host in Connecting Two Virtual Machines. Make sure when you configure the target virtual machine's virtual serial port that you select the Yield CPU on poll check box, as the kernel in the target virtual machine uses the virtual serial port in polled mode, not interrupt mode.
To prepare the debugger virtual machine, make sure you have downloaded Debugging Tools for Windows. Then follow the steps for the client virtual machine in Connecting Two Virtual Machines.
When you are ready to begin, complete the following steps:
- Power on both virtual machines.
- Check to make sure the serial port is connected in each virtual machine. On the Devices menu, serial<n> should say .pipe<namedpipe> (Windows hosts) or /tmp/<socket> (Linux hosts). Note: If the serial<n> says (Not connected), then the serial port may not be connected. Choose the virtual serial port, then Connect.
- In the debugger virtual machine, start debugging with WinDbg or KD normally.
What is Redirection?
Redirection is a feature in Linux such that when executing a command, you can change the standard input/output devices. The basic workflow of any Linux command is that it takes an input and give an output.
- The standard input (stdin) device is the keyboard.
- The standard output (stdout) device is the screen.
With redirection, the above standard input/output can be changed.
In this tutorial, we will learn-
Click here if the video is not accessible
Output Redirection
The '>' symbol is used for output (STDOUT) redirection.
Example:
Here the output of command ls -al is re-directed to file 'listings' instead of your screen.
Note: Use the correct file name while redirecting command output to a file. If there is an existing file with the same name, the redirected command will delete the contents of that file and then it may be overwritten.'
If you do not want a file to be overwritten but want to add more content to an existing file, then you should use '>>' operator.
You can redirect standard output, to not just files, but also devices!
The cat command reads the file music.mp3 and sends the output to /dev/audio which is the audio device. If the sound configurations in your PC are correct, this command will play the file music.mp3
Input redirection
The '<' symbol is used for input(STDIN) redirection
Example: The mail program in Linux can help you send emails from the Terminal.
You can type the contents of the email using the standard device keyboard. But if you want to attach a File to email you can use the input re-direction operator in the following format.
This would attach the file with the email, and it would be sent to the recipient.
The above examples were simple. Let's look at some advance re-direction techniques which make use of File Descriptors.
File Descriptors (FD)
In Linux/Unix, everything is a file. Regular file, Directories, and even Devices are files. Every File has an associated number called File Descriptor (FD).
Your screen also has a File Descriptor. When a program is executed the output is sent to File Descriptor of the screen, and you see program output on your monitor. If the output is sent to File Descriptor of the printer, the program output would have been printed.
Error Redirection
Whenever you execute a program/command at the terminal, 3 files are always open, viz., standard input, standard output, standard error.
These files are always present whenever a program is run. As explained before a file descriptor, is associated with each of these files. File | File Descriptor |
---|---|
Standard Input STDIN | 0 |
Standard Output STDOUT | 1 |
Standard Error STDERR | 2 |
By default, error stream is displayed on the screen. Error redirection is routing the errors to a file other than the screen.
Why Error Redirection?
Error re-direction is one of the very popular features of Unix/Linux.
Frequent UNIX users will reckon that many commands give you massive amounts of errors.
- For instance, while searching for files, one typically gets permission denied errors. These errors usually do not help the person searching for a particular file.
- While executing shell scripts, you often do NOT want error messages cluttering up the normal program output.
The solution is to re-direct the error messages to a file.
Example 1
Above we are executing a program names myprogram.
The file descriptor for standard error is 2.
Using '2>' we re-direct the error output to a file named 'errorfile'
Thus, program output is not cluttered with errors.
Example 2
Here is another example which uses find statement -
Using the 'find' command, we are searching the '.' current directory for a file with 'name' starting with 'my'
Example 3 Let's see a more complex example,
Server Administrators frequently, list directories and store both error and standard output into a file, which can be processed later. Here is the command.
Here,
- which writes the output from one file to the input of another file. 2>&1 means that STDERR redirects to the target of STDOUT (which is the file dirlist)
- We are redirecting error output to standard output which in turn is being re-directed to file dirlist. Hence, both the output is written to file dirlist
Summary
- Each file in Linux has a corresponding File Descriptor associated with it
- The keyboard is the standard input device while your screen is the standard output device
- '>' is the output redirection operator. '>>' appends output to an existing file
- '<' is the input redirection operator
- '>&'re-directs output of one file to another.
- You can re-direct error using its corresponding File Descriptor 2.