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

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.