12. Running a DOS application directly from Unix shell

This part of the document was written by Hans <lermen@fgan.de>.

This chapter deals with starting DOS commands directly from Linux. You can use this information to set up icons or menu items in X. Using the keystroke, input and output redirection facilities you can use DOS commands in shell scripts, cron jobs, web services, and so on.

12.1. Using unix -e in autoexec.bat

The default autoexec.bat file has a statement unix -e at the end. This command executes the DOS program or command that was specified on the dosemu command line.

For example:

    dosemu "/home/clarence/games/commander keen/keen1.exe"
will automatically:

Using "-E" at the command line causes DOSEMU to continue after the DOS program finishes.

You can also specify a DOS command, such as "dir". A combination with the -dumb command-line option is useful if you want to retrieve the output of the DOS command, such as

    dosemu -dumb dir > listing
In this case (using -dumb, but not -E) all the startup messages that DOSEMU and DOS generate are suppressed and you only get the output of "dir". The output file contains DOS end-of-line markers (CRLF).

12.2. Using the keystroke facility.

Make use of the -input command-line option, such as

    dosemu -input 'dir > C:\\garbage\rexitemu\r'
The '...' will be 'typed in' by DOSEMU exactly as if you had them typed at the keyboard. The advantage of this technique is, that all DOS applications will accept them, even interactive ones. A '\' is interpreted as in C and leads in ESC-codes. Here is a list of the current implemented ones:

    \r     Carriage return == <ENTER>
    \n     LF
    \t     tab
    \b     backspace
    \f     formfeed
    \a     bell
    \v     vertical tab
    
    
    \^x    <Ctrl>x, where X is one of the usual C,M,L,[ ...
           (e.g.: \^[ == <Ctrl>[ == ESC )
    
    \Ax    <Alt>x, hence  \Ad means <Alt>d
    
    \Fn;   Function key Fn. Note that the trailing ';' is needed.
           (e.g.:  \F10;  == F10 )
    
    \Pn;   Set the virtual typematic rate, thats the speed for
           autotyping in. It is given in unix timer ticks to wait
           between two strokes. A value of 7 for example leads to
           a rate of 100/7=14 cps.
    
    \pn;   Before typing the next stroke wait n unix ticks.
           This is useful, when the DOS-application flushes the
           keyboard buffer on startup. Your strokes would be discarded,
           if you don't wait.
    

12.3. Using an input file

In bash you can also use

    echo -e 'dir \gt; c:\\garbage\rexitemu\r' | dosemu -dumb
or, when your dos-app does only normal printout (text), then you may even do this
    echo -e 'dir\rexitemu\r' | dosemu -dumb > FILE.out

FILE.out then contains the output from the DOS application, but (unlike the unix -e technique, merged with all startup messages.

You may elaborate this technique by writing a script, which gets the dos-command to execute from the commandline and generate 'FILE' for you.

12.4. Running DOSEMU within a cron job

When you try to use one of the above to start DOSEMU out of a crontab, then you have to asure, that the process has a proper environment set up ( especially the TERM and/or TERMCAP variable ).

Normally cron would setup TERM=dumb, this is fine because DOSEMU recognizes it and internally sets it's own TERMCAP entry and TERM to `dosemu-none'. You may also configure your video to

       dosemu ... -dumb
or have a TERM=none to force the same setting. In all other crontab run cases you may get nasty error messages either from DOSEMU or from Slang.