Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to test for missing parm with batch FOR command

Posted on 2004-08-30
2
Medium Priority
?
181 Views
Last Modified: 2010-04-13
I have a batch script which uses the FOR command to read a file of parameters.  The parameters are 2 per line and separated by a semicolon.  How can determine if a semicolon was not used?  Here is what I've tried so far:
for /F "tokens=1,2,* skip=1 delims=;" %%A in (%1) do (if %%B == "" echo missing semicolon)  It would be nice if I could also distiguish between a missing semicolon and a missing second parameter.  

0
Comment
Question by:rdclk23
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 11936441
Basically, there's not too much of a difference between a missing delimiter and a missing argument, but the check is possible.
Note that I used "in 'type %1'" instead of "in (%1)"; this prevents problems if %1 contains spaces.
And in case you see the "call :<label>" construction for the first time: this is the batch version of a subroutine call. Enter "help call" for more information.

@echo off
setlocal
for /f "skip=1 delims=" %%a in ('type %1') do (
  set Line=%%~a
  call :process
)
goto leave

:process
if "%Line%"=="%Line:;=%" (
  echo Missing delimiter: %Line%
  goto :eof
)
for /f "tokens=1,2 delims=;" %%a in ("%Line%") do (
  set Arg1=%%~a
  set Arg2=%%~b
)
if "%Arg2%"=="" (
  echo Missing argument:  %Line%
  goto :eof
)
echo Correct arguments: [%Arg1%][%Arg2%]
:: *** Handle your arguments here:
:: ...
goto :eof


:leave
0
 

Author Comment

by:rdclk23
ID: 12048091
Thanks!  Worked Great!  It took me a while to figure out what "%Line:;=" was doing, but I now see that you are using string replacement.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question