FacetWin Logo  
 
FacetCorp
 

PC Command for Profit and Fun!

By Eric Yundt


NOTE: This FacetWin technical application article originally appeared in FacetNews, the FacetCorp newsletter, Vol. 5, Issue 3. In it are examples of using FacetWin's PC Command feature to control Windows applications from the UNIX system. If you have trouble trying to use any of these ideas, please contact FacetCorp technical support for assistance.

What it is:

FacetWin's "PC Command" feature can be a nifty way to control MS Windows applications from within your UNIX character-based applications. Regular UNIX "shell" scripts can launch Windows image viewers, UNIX log-files can be analyzed with Windows spreadsheets, and UNIX applications can print using Windows printer drivers -- it just takes a little FacetWin "PC Command" cleverness. This means that PCs using FacetWin can now do what once required expensive X-Windows graphical workstations by tapping the power of UNIX databases and using pretty Windows tools to view the exotic data. For instance, end-users of a medical application could display high-resolution x-rays on their PCs - with a single key-stroke to the UNIX application! Or your UNIX character-based applications could send audible error messages to the PC user via the PC's sound system - now wouldn't that be slick!

The "PC Command" (or "Run Program Escape Sequence") feature uses a special escape sequence sent to the FacetWin terminal emulator. This sequence specifies a Windows application startup command that is "launched" on the PC by the FacetWin Terminal. As simple as this can be, there are often questions about implementing this powerful FacetWin feature. An overview with examples of using this feature can be found in the FacetWin manual section, FacetWin Terminal Emulator: Additional Escape Sequences, or in the FacetWin Windows helpfile under:

FacetWin Terminal Emulator / Advanced Topics / Additional Escape Sequences

How it works:

The "Run Program Escape Sequence" must be enabled on the FacetWin Terminal property sheet before this special escape sequence will work. The checkbox to enable this escape sequence is at the bottom of the property sheet's "Options" tab.

The escape sequence syntax is:

       \E [ 2 ] command argument(s) \r

where:

      \E is the escape character (0x1B)
[ 2 ]
 
is literally, left-square bracket (0x5B), 2,
and right-square bracket (0x5D)
command is the Windows command to execute
argument(s)    
 
are the Windows command line argument(s), if any,
separated from command by a space
\r is the carriage-return character (0x0D)

There are many ways to send an escape sequence to the screen from a UNIX application (or shell) and depending upon your circumstances, you may find that one method is easier to implement than others. As far as FacetWin is concerned, it does not matter how the escape sequence is sent to the screen, but just that the end result sent to the screen is the complete escape sequence. Some common ways to do this are:

Now for the fun!       ;-)

Imagine your typical character-based Toy Store inventory application - efficient but perhaps a little drab. You've got your standard Add, Delete, Modify, etc. options, but with FacetWin's PC Command feature you can now offer a "View" option! With it, when the end-user hits "v" for View, up pops a Windows image viewer with a pretty picture of the inventory item - or the images could be popped up automatically while scrolling through the inventory list.

There are many, many ways to accomplish this through FacetWin. Skip to the last paragraph if you would rather have your computer guy or gal deal with the specifics, otherwise buckle your seatbelt and read on!       B^)

In this example, let's assume a few things:


Here is an excerpt from a simple UNIX shell script that processes the inventory application options and uses FacetWin's PC Command feature to display an image.

     SEQ="\033[2]"            # PC Command escape sequence
     VIEWER=""                # null command uses default viewer
     [ "$VIEWER" ] && S=" "   # otherwise need space after command
     IDIR="I:"                # mapped to \\UNIX\IMAGEDIR
     EXT="GIF"                # image file extension
	
     while [ "$KEY" != q ]
     do
        ReadKey               # returns key pressed in $KEY

        case $KEY in

           v) ### view image options
              echo "${SEQ}${VIEWER}${S}${IDIR}${PARTNO}.${EXT}\r"
              ;;
           *) ### other command options
              ;;
        esac
     done
In this case if the "$PARTNO" variable contained "1QNN035" then the complete escape sequence sent to the FacetWin Terminal window (with null viewer command) would be:
     ESC [ 2 ] I:1QNN035.GIF \r
If you had a DOS batch file used to launch the image viewer, you could just change the "$VIEWER" variable to the name of the batch file:
   VIEWER="C:\SEEIMAGE.BAT"
And then the escape sequence sent would be:
   ESC [ 2 ] C:\SEEIMAGE.BAT I:1QNN035.GIF \r
Or to directly use Microsoft's PhotoEditor to view the image (which is found at the end of a very long path) you could use the DOS 8.3 file naming convention to avoid spaces in the command name which could be misinterpreted as the separator between command and argument(s):
   VIEWER="c:\progra~1\\\\common~1\micros~1\photoed\photoed"
Note, the special protection needed for the "\c" at the beginning of "\common~1" to protect it from being interpreted by the "echo" command and UNIX shell. This results in:
   ESC [ 2 ] c:\progra~1\common~1\micros~1\photoed\photoed I:1QNN035.GIF \r
Which can be verified by piping the "echo" command into the "od -c" command.

OK! You can relax, the tough stuff is over! You can find a working example of this shell script and related files available for download (so you can show your friends how slick you are!) from our webpage at:

      /tnotes/facetwin/SeeToys - shell script only
      /tnotes/facetwin/pc-command.cpio - GIFs, screens & script
            (to extract files, do "cpio -icv < pc-command.cpio")

Last Paragraph:

There are many ways you can enhance your character-based UNIX applications with this neat FacetWin feature. Things that used to require an expensive X-Windows graphical workstation can now be done from a simple PC connected to the UNIX box via FacetWin. From your medical application, you could easily view x-rays or sonograms. From a real estate database, you could pop-up pretty pictures of the homes. And this feature is certainly not restricted to showing pretty pictures. You could use your UNIX accounting application to generate raw data and then display it in a Windows spread-sheet pie-chart or bar-graph. UNIX databases could display data in specially formatted HTML tables using a Windows web-browser. Or this feature could even be used to pass program data to a Windows application, for example, you could pass a Customer ID# from a UNIX database to a Windows database on the command line.

Like some other ideas? Or need help customizing this feature to add value to your UNIX experience?

Contact your FacetWin reseller or FacetCorp now... and let the brainstorm begin!

Eric Yundt is a member of the FacetCorp Technical Support staff and is also the FacetCorp WebMaster. He can be reached at (972) 985-9901 or by email at "support@facetcorp.com".