Here's a shell script I've been using and improving
for the last two years.  It executes a series of DOS com-
mands in the current directory, without interfering with
any other active DOSemu processes.

     Usage is pretty simple:

dodos 2m << xx
bcc -N -Z -O -ml -I. cbrom.c expand.c compress.c public.c
exitemu
xx

     or

echo -e "dir > dosdir\nexitemu" | dodos

     The "2m" is optional; it's a new feature that says,
"If DOSemu doesn't finish in two minutes, kill it."  It's
very helpful when I want to do an overnight build of 500
BIOS parts, and the 20th one locks up with "Memory allo-
cation error, System Halted".

                                Dave Coffin  7/31/99
#!/bin/bash2
# "dodos" executes a list of DOS commands from standard input
# Dave Coffin  12/3/97

# $Revision: 1.8 $
# $Date: 1999/07/27 14:29:53 $

# All DOS batch files MUST have carriage returns!!
cr()
{
  awk '{ print $0 "\r" }'
}

# OK, here's the procedure:  c:\autoexec.bat does
#
#       lredir d: linux\fs\
#       d:
#       \tmp\dosemu\auto
#
# /tmp/dosemu/auto.bat chdir's to the current UNIX directory
# (assuming the path contains only DOS-legal names), and exe-
# cutes aut$$.bat.  The first thing aut$$.bat does is delete
# /tmp/dosemu/auto.bat, so that another dosemu process can use
# it.  Got that?

# User-specified commands go into aut$$.bat.
echo 'del d:\tmp\dosemu\auto.bat' | cr > aut$$.bat
cr >> aut$$.bat

# If another dosemu is using auto.bat, we must wait.
error='Waiting for /tmp/dosemu/auto.bat to be deleted.'
while [ -f /tmp/dosemu/auto.bat ]
do
  echo -n "$error" >&2
  sleep 1
  error=.
done
[ "$error" = . ] && echo ok

# Create our auto.bat file.
mkdir -p -m 777 /tmp/dosemu
cr << xx > /tmp/dosemu/auto.bat
echo on
d:
cd `pwd | tr / '\\\\'`
aut$$
xx

# If the user requests a timeout, start a watchdog process.
if [ -n "$1" ]
then
  sleep $1 && kill -9 `ps ww | awk '/ dos$/ { print $1 }'` &
  watchdog=$!
fi

# Run DOS, with stdin coming from the current tty
dos < `tty <&2`

# When the DOS commands are done, the user will be left at a
# working DOS prompt, unless the last command was "exitemu".

# Get rid of the watchdog process.
[ -n "$watchdog" ] && kill $watchdog

rm aut$$.bat
head    1.8;
access;
symbols;
locks; strict;
comment @# @;


1.8
date    99.07.27.14.29.53;      author dcoffin; state Exp;
branches;
next    1.7;

1.7
date    99.07.26.23.30.54;      author dcoffin; state Exp;
branches;
next    1.6;

1.6
date    99.07.23.20.52.09;      author dcoffin; state Exp;
branches;
next    1.5;

1.5
date    98.06.19.22.43.36;      author dcoffin; state Exp;
branches;
next    1.4;

1.4
date    98.04.10.21.35.29;      author dcoffin; state Exp;
branches;
next    1.3;

1.3
date    97.12.03.17.40.38;      author dcoffin; state Exp;
branches;
next    1.2;

1.2
date    97.12.03.17.30.34;      author dcoffin; state Exp;
branches;
next    1.1;

1.1
date    97.12.03.17.28.27;      author dcoffin; state Exp;
branches;
next    ;


desc
@Script to read commands from standard input and execute
them in DOS.  It should work in the current directory.
Rev. 1.1 was written 9/18/97
@


1.8
log
@Kill DOSemu, not dodos.  That way, we can still clean up
at the end.
@
text
@#!/bin/bash2
# "dodos" executes a list of DOS commands from standard input
# Dave Coffin  12/3/97

# $Revision$
# $Date$

# All DOS batch files MUST have carriage returns!!
cr()
{
  awk '{ print $0 "\r" }'
}

# OK, here's the procedure:  c:\autoexec.bat does
#
#       lredir d: linux\fs\
#       d:
#       \tmp\dosemu\auto
#
# /tmp/dosemu/auto.bat chdir's to the current UNIX directory
# (assuming the path contains only DOS-legal names), and exe-
# cutes aut$$.bat.  The first thing aut$$.bat does is delete
# /tmp/dosemu/auto.bat, so that another dosemu process can use
# it.  Got that?

# User-specified commands go into aut$$.bat.
echo 'del d:\tmp\dosemu\auto.bat' | cr > aut$$.bat
cr >> aut$$.bat

# If another dosemu is using auto.bat, we must wait.
error='Waiting for /tmp/dosemu/auto.bat to be deleted.'
while [ -f /tmp/dosemu/auto.bat ]
do
  echo -n "$error" >&2
  sleep 1
  error=.
done
[ "$error" = . ] && echo ok

# Create our auto.bat file.
mkdir -p -m 777 /tmp/dosemu
cr << xx > /tmp/dosemu/auto.bat
echo on
d:
cd `pwd | tr / '\\\\'`
aut$$
xx

# If the user requests a timeout, start a watchdog process.
if [ -n "$1" ]
then
  sleep $1 && kill -9 `ps ww | awk '/ dos$/ { print $1 }'` &
  watchdog=$!
fi

# Run DOS, with stdin coming from the current tty
dos < `tty <&2`

# When the DOS commands are done, the user will be left at a
# working DOS prompt, unless the last command was "exitemu".

# Get rid of the watchdog process.
[ -n "$watchdog" ] && kill $watchdog

rm aut$$.bat
@


1.7
log
@Use $! to get the PID of a background process.  Wish I knew
that last Friday...
@
text
@d52 1
a52 1
  sleep $1 && kill $$ &
@


1.6
log
@Re-wrote the comments and added a timeout feature.
@
text
@d49 6
a54 7
# If the user requests a timeout, start this watchdog script
# in the background.
[ -n "$1" ] &&
{
  sleep $1 &&
  kill `ps ww | awk '/ dos$/ { print $1 }'`
} &
d62 2
a63 3
# Stop the watchdog script before it kills an innocent dos
# process.
[ -n "$1" ] && kill `ps ww | awk '/ sleep / { print $1 }'`
@


1.5
log
@Modified dodos and xdos to work with multiple users,
by moving auto.bat into the /tmp directory.
@
text
@d1 1
a1 1
#!/bin/bash
d5 3
d14 5
a18 2
# Put some commands in /tmp/dosemu/auto.bat.  This gets called
# from the C:\AUTOEXEC.BAT file (not visible from Linux)
d20 9
a28 4
# There can be only one /tmp/dosemu/auto.bat, whereas I may wish
# to run multiple dodos's at once.  So have /tmp/dosemu/auto.bat
# call a uniquely named file in the current directory.  The first
# thing it does is delete /tmp/dosemu/auto.bat:
d30 2
a31 1
error='Waiting for /tmp/dosemu/auto.bat to get deleted.'
d40 1
d49 7
a55 5
echo 'del d:\tmp\dosemu\auto.bat' | cr > aut$$.bat

# Now read DOS commands from stdin

cr >> aut$$.bat
a57 1

d62 4
@


1.4
log
@Cosmetic improvements to the wait loop
@
text
@d11 2
a12 2
# Put some commands in ~/auto.bat.  This gets called from the
# C:\AUTOEXEC.BAT file (not visible from Linux)
d14 4
a17 4
# There can be only one ~/auto.bat, whereas I may wish to run
# multiple dodos's at once.  So have ~/auto.bat call a uniquely
# named file in the current directory.  The first thing it does
# is delete ~/auto.bat:
d19 2
a20 2
error='Waiting for ~/auto.bat to get deleted.'
while [ -f ~/auto.bat ]
d28 2
a29 1
cr << xx > ~/auto.bat
d36 1
a36 1
echo 'del d:\home\dcoffin\auto.bat' | cr > aut$$.bat
@


1.3
log
@Updated DOS paths to reflect the new directory structure.
@
text
@d19 1
d22 3
a24 2
  echo "Waiting for ~/auto.bat to get deleted..." >&2
  sleep 2
d26 1
@


1.2
log
@Enhanced dodos script to make it re-entrant.
last modified 11/12/97
@
text
@d3 1
a3 1
# Dave Coffin  9/22/97
a10 11
# Figure out the DOS path to the current directory

case $PWD/ in
  /dos/*)  dosdisk=D: ;;
  /home/*) dosdisk=E: ;;
  *) echo "Current directory is not accessible from DOS!!" >&2
     exit 1
esac

dosdir=\\`pwd | cut -d/ -f3- | tr / '\\\\'`

d27 2
a28 2
$dosdisk
cd $dosdir
d32 1
a32 1
echo 'del e:\dcoffin\auto.bat' | cr > aut$$.bat
@


1.1
log
@Initial revision
@
text
@d3 7
a9 1
# Dave Coffin  9/18/97
d13 1
a13 1
case $PWD in
d22 13
a34 2
# In dosemu, c:\autoexec.bat calls e:\dcoffin\auto.bat
# Note that all batch files MUST have carriage returns!!
d36 1
a36 1
awk '{ print $0 "\r" }' << xx    > ~/auto.bat
d40 1
d43 8
a50 1
awk '{ print $0 "\r" }'         >> ~/auto.bat
d53 2
a54 2
# Unless auto.bat does an "exitemu", the user will be left at
# the DOS prompt when auto.bat completes.
d56 1
a56 1
rm ~/auto.bat
@

Reply via email to