I'm still running MS-DOS 6.21 and have a lot of fun writing batch files for it.
I'm wondering if there's a way to enter an empty string as a parameter when running a batch file.
The batch file would be run from a macro executed by my text editor.
And the parameter would sometimes contain text, and sometimes be empty.
What I'm trying to figure out is how to preserve the order of the parameters if one of them in the middle of the sequence of parameters should turn up empty. So I guess you could say what I'm looking for is a way to pass a "place holder" parameter to a batch file in cases where that parameter string comes up empty.
Here's a simplified example: Suppose the three parameters are:
%1 DIRECTORY_NAME
%2 [empty string]*
%3 FILE_NAME
Is there a way to write a command line to run the batch file that would pass parameter %2 to the batch file as an empty string?
Will in Seattle
a.k.a. "Clueless"
*In case you're wondering, parameter %2 is used for the name of a sub-directory (if any). Sometimes there will be one, and sometimes not.
Enter empty string as parameter from DOS command prompt?
Moderator: DosItHelp
-
- Posts: 47
- Joined: 01 Jul 2011 13:37
Re: Enter empty string as parameter from DOS command prompt?
I fear you can't pass an empty string but you could check if %3 is present.
... where you should assume that %2 contains the file name.
Regards
aGerman
EDIT:
Maybe this could work for you
Code: Select all
IF _%3==_ (your command here)
... where you should assume that %2 contains the file name.
Regards
aGerman
EDIT:
Maybe this could work for you
Code: Select all
FOR %%I IN (DIRECTORY_NAME SUBDIR_NAME FILE_NAME) DO SET %%I=
SET DIRECTORY_NAME=%1
SET FILE_NAME=%3
IF DEFINED FILE_NAME (SET SUBDIR_NAME=%2) ELSE SET FILE_NAME=%2
Re: Enter empty string as parameter from DOS command prompt?
Pass it as an empty quoted string
Code: Select all
@echo off
echo parm1 is %~1
echo parm2 is %~2
echo parm3 is %~3
pause
Code: Select all
C:\Batch>parms.bat "Foo1" "" "Foo3"
parm1 is Foo1
parm2 is
parm3 is Foo3
-
- Posts: 47
- Joined: 01 Jul 2011 13:37
Re: Enter empty string as parameter from DOS command prompt?
Squashman wrote:Pass it as an empty quoted stringCode: Select all
C:\Batch>parms.bat "Foo1" "" "Foo3"
Thanks, Squashman.
So, does that mean that all the other parameters have to be enclosed in quotes as well, for this to work?
Will in Seattle
a.k.a. "Clueless"
Re: Enter empty string as parameter from DOS command prompt?
The parameters don't have to be enclosed in quotes, but if an empty argument isn't enclosed in quotes, there is no argument at all.Clueless in Seattle wrote:Squashman wrote:Pass it as an empty quoted stringCode: Select all
C:\Batch>parms.bat "Foo1" "" "Foo3"
Thanks, Squashman.
So, does that mean that all the other parameters have to be enclosed in quotes as well, for this to work?
Will in Seattle
a.k.a. "Clueless"
Spaces and tabs are delimiters thus not valid arguments. This is why an empty argument must be quoted so the receiver has a way of knowing the argument has value empty.
Computer languages and programs often use;
Code: Select all
myProgram /argName: value /argName: "v a l u e" /argName: "" /aSwitch /anotherSwitch