Windows CE: Running Batch Files

<< Platform Builder: Cloning an MDD Lib | Home | Platform Builder: Sources Files 2 >>

Every once in a while I am asked about running batch files on Windows CE. My first response of course to ask why? But let’s assume that you are set on using a batch file. I know you probably think that batch files are easy to modify, but really I don’t think that they are and you may find that batch files for Windows CE aren’t that easy.

The first thing that you are going to need is a Command window, or DOS shell, to run your batch file in.   It is likely that your system doesn’t have one, but if you have control over the content of your Windows CE OS ROM image, you can add one using Platform Builder or have your OS team to add one.   If you don’t have one and don’t have control over the OS, then you will need to find one that you can use. I do have control over my OS, so I have never needed to look for one.

To demonstrate that batch files can run in Windows CE, and to check for some of the shortcomings, I created the following batch file:

@ECHO OFF

echo Running Batch.bat

set LOGOFILE="\Release\Logo.jpg"

set TESTFILE="\Release\Test.txt"

if EXIST %LOGOFILE% xcopy %LOGOFILE% \Windows

if EXIST %LOGOFILE% copy %LOGOFILE% \Windows

for /F %%i in (%TESTFILE%) Do (

                echo %%i

                )

CALL :ListDirs

Pushd \Windows

Dir /A:D

Popd

GOTO :EOF

:ListDirs

cd %1

for /F %%i in ('dir /A:D /B /S \Windows' ) Do (

                                Echo Dir %%i

                 )

GOTO :EOF

Careful, don’t think that everything in this file works. Some things do not work:

1.       Xcopy isn’t available, but copy is

2.       For loops aren’t suppprted, but if statements are

3.       Call is supported, but not to functions in the batch file

4.       Pushd and Popd aren’t supported, but cd is

I am sure that if I kept adding things to this batch file, I would have found more unsupported features that are supported in big Windows or DOS.

I think that it might be easier to write a simple application to do most of what you might want to do in a batch file. You can write an application that uses main() for Windows CE, and have for loops. But I am a C programmer so what is easy to me might not be so easy for you.

Copyright © 2008 – Bruce Eitman

All Rights Reserved

Thursday, August 21, 2008 7:53 PM

This article is part of the GWB Archives. Original Author: Bruce Eitman

New on Geeks with Blogs