Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem passing parameter with "%" character

190 views
Skip to first unread message

JJ

unread,
Jun 1, 2012, 6:12:24 PM6/1/12
to
Hello,

I'm trying to pass file path as a parameter to a console program. e.g.:
C:\PROG.EXE "C:\The File"

This command line is executed from another program (call it PROG2).
Since I need to see the result, I use 4NT and PAUSE command like so:
C:\4NT\4NT.EXE /C C:\PROG.EXE "C:\The File" & PAUSE

It works most of the time, but not if the file contains "%" (percent)
character(s). e.g.:
C:\4NT\4NT.EXE /C C:\PROG.EXE "C:\File%With%Percent" & PAUSE

The result is that 4NT execute the program as:
C:\PROG.EXE "C:\FilePercent"
instead of:
C:\PROG.EXE "C:\File%With%Percent"

Strange thing is, it works OK if I use CMD instead of 4NT.

I have various kind of file names. Some even contains "&" characters and
unicodes, so my current full command is like:
C:\4NT\4NT.EXE /U /C SETDOS/C¬ %+ C:\PROG.EXE $file$ %+ PAUSE
The above "$file$" is used by PROG2 to substitute file path.

So how can I make 4NT works like CMD in this specific case?

Thank you in advance.

E. S. Fabian

unread,
Jun 1, 2012, 7:59:50 PM6/1/12
to
JJ:

| So how can I make 4NT works like CMD in this specific case?

You cannot do it reliably (i.e. you cannot guarantee that any filename
accepted by the OS will work in 4DOS, 4NT, TCC/LE or TCC). The syntax of the
language used by 4NT goes back to the times when very few characters other
than letters and numerals were permitted in filenames. The very things which
made 4DOS and its successors worth buying are now often detrimental. I don't
know why CMD works in your case... or does it really?
--
Steve


JJ

unread,
Jun 1, 2012, 8:57:21 PM6/1/12
to
E. S. Fabian wrote:
> You cannot do it reliably (i.e. you cannot guarantee that any filename
> accepted by the OS will work in 4DOS, 4NT, TCC/LE or TCC). The syntax of the
> language used by 4NT goes back to the times when very few characters other
> than letters and numerals were permitted in filenames. The very things which
> made 4DOS and its successors worth buying are now often detrimental. I don't
> know why CMD works in your case... or does it really?

CMD does work. Really.
You can reproduce this using the following steps:

1. Create a batch file as "C:\TEST.CMD" with contents:
@ECHO OFF
ECHO PARAM1=%1
PAUSE

2. Create a new file and name it as "C:\File%With%Percent".

3. Create a shortcut as "C:\4NT Test.lnk" for 4NT then change the target
(via its properties) to:
C:\4NT\4NT.EXE /C C:\TEST.CMD

4. Create a shortcut as "C:\CMD Test.lnk" for CMD then change the target
(via its properties) to:
%windir%\system32\cmd.exe /C C:\TEST.CMD

5. Test 4NT by dragging "C:\File%With%Percent" onto "C:\4NT Test.lnk".

6. Test CMD by dragging "C:\File%With%Percent" onto "C:\CMD Test.lnk".

TCC/LE also have the same problem.

I can use CMD if I have to, but AFAIK, CMD can't disable command separator.

Michael Bednarek

unread,
Jun 2, 2012, 2:20:34 AM6/2/12
to
On Sat, 02 Jun 2012 05:12:24 +0700, JJ wrote in comp.os.msdos.4dos:

>Hello,
>
>I'm trying to pass file path as a parameter to a console program. e.g.:
>C:\PROG.EXE "C:\The File"
>
>This command line is executed from another program (call it PROG2).
>Since I need to see the result, I use 4NT and PAUSE command like so:
>C:\4NT\4NT.EXE /C C:\PROG.EXE "C:\The File" & PAUSE
>
>It works most of the time, but not if the file contains "%" (percent)
>character(s). e.g.:
>C:\4NT\4NT.EXE /C C:\PROG.EXE "C:\File%With%Percent" & PAUSE
[snip]

It should work if PROG2 can sanitise the filename. There are (at least)
two possibilities: 1) double the %-sign; 2) more reliably, precede the
%-sign with "%=", the internal pseudovariable containing the escape
character.

--
Michael Bednarek "ONWARD"

Laurent Jumet

unread,
Jun 2, 2012, 2:47:01 AM6/2/12
to

Hello JJ !

JJ <jaej...@googlemail.com> wrote:

> I'm trying to pass file path as a parameter to a console program. e.g.:
> C:\PROG.EXE "C:\The File"
> This command line is executed from another program (call it PROG2).
> Since I need to see the result, I use 4NT and PAUSE command like so:
> C:\4NT\4NT.EXE /C C:\PROG.EXE "C:\The File" & PAUSE

I'm using TCC 11.0 (I was using 4NT earlier) and in TCC you may write the whole command at the PROMPT, and press Ctrl-X to see how all those variables are expanding.


Example: This is a command at the PROMPT (do not press Enter at this time):

C:\PROG.EXE "C:\File %SystemRoot% %CLIENTNAME% Percent" & PAUSE

Now, pressing Ctrl-X gives this:

C:\PROG.EXE "C:\File C:\WINDOWS Console Percent" & PAUSE

So you can exactly see how variables will be expanded.
I suggest you to try Ctrl-X (I don't rememeber if it exists in 4NT).

You may want to upgrade to TakeCommand/TCC (must pay) or to TCC_LE (free but some functions are disabled).

--
Laurent Jumet - Point de Chat, Liège, BELGIUM
KeyID: 0xCFAF704C
[Restore address to laurent.jumet for e-mail reply.]

Klaus Meinhard

unread,
Jun 2, 2012, 7:41:33 AM6/2/12
to
Hey JJ,

have a look at the SETDOS /x-n1234... command help.

I 4DOS time you could overcome nearly any character problem with this.

--
Best regards,

* Klaus Meinhard *
<www.4dos.info>

JJ

unread,
Jun 2, 2012, 6:08:10 PM6/2/12
to
On Sat, 2 Jun 2012 13:41:33 +0200, "Klaus Meinhard" <K_Mei...@gmx.de> wrote:

>Hey JJ,
>
>have a look at the SETDOS /x-n1234... command help.
>
>I 4DOS time you could overcome nearly any character problem with this.

The /X-3 works well.
C:\4NT\4NT.EXE /U /C SETDOS/X-3 & C:\PROG.EXE $file$ & PAUSE
I already have /X-4 as my default setting, but it doesn't seem to apply to double-quoted text.

I also need file name processing for other programs. e.g.:
"C:\Really &Difficult %Folder" becomes "C:\Really &Difficult %Folder\*"
Simple append like "C:\Really &Difficult %Folder"\* would not be a valid Windows file specifier.

I guess I'll just have to make my own program for this.

JJ

unread,
Jun 2, 2012, 6:10:22 PM6/2/12
to
On Sat, 02 Jun 2012 16:20:34 +1000, Michael Bednarek <mbATmbed...@BLACKHOLESPAM.NET> wrote:
>It should work if PROG2 can sanitise the filename. There are (at least)
>two possibilities: 1) double the %-sign; 2) more reliably, precede the
>%-sign with "%=", the internal pseudovariable containing the escape
>character.

Unfortunately, it can't.

JJ

unread,
Jun 2, 2012, 6:12:25 PM6/2/12
to
On Sat, 02 Jun 2012 08:47:01 +0200, "Laurent Jumet" <1st_NAME...@skynet.be> wrote:
>
>Hello JJ !
>
> I'm using TCC 11.0 (I was using 4NT earlier) and in TCC you may write the whole command at the PROMPT, and press Ctrl-X to see how all those variables are expanding.
>
>
>Example: This is a command at the PROMPT (do not press Enter at this time):
>
>C:\PROG.EXE "C:\File %SystemRoot% %CLIENTNAME% Percent" & PAUSE
>
> Now, pressing Ctrl-X gives this:
>
>C:\PROG.EXE "C:\File C:\WINDOWS Console Percent" & PAUSE
>
> So you can exactly see how variables will be expanded.
> I suggest you to try Ctrl-X (I don't rememeber if it exists in 4NT).
>
> You may want to upgrade to TakeCommand/TCC (must pay) or to TCC_LE (free but some functions are disabled).

The PROG.EXE is executed by another program (a frontend) and not from a command prompt.

JJ

unread,
Jun 2, 2012, 6:17:21 PM6/2/12
to
On Sat, 02 Jun 2012 08:47:01 +0200, "Laurent Jumet" <1st_NAME...@skynet.be> wrote:
>
>Hello JJ !
>
> I'm using TCC 11.0 (I was using 4NT earlier) and in TCC you may write the whole command at the PROMPT, and press Ctrl-X to see how all those variables are expanding.
>
>
>Example: This is a command at the PROMPT (do not press Enter at this time):
>
>C:\PROG.EXE "C:\File %SystemRoot% %CLIENTNAME% Percent" & PAUSE
>
> Now, pressing Ctrl-X gives this:
>
>C:\PROG.EXE "C:\File C:\WINDOWS Console Percent" & PAUSE
>
> So you can exactly see how variables will be expanded.
> I suggest you to try Ctrl-X (I don't rememeber if it exists in 4NT).
>
> You may want to upgrade to TakeCommand/TCC (must pay) or to TCC_LE (free but some functions are disabled).

I rarely use that shortcut. Thanks for the reminder.

Laurent Jumet

unread,
Jun 3, 2012, 12:32:22 AM6/3/12
to

Hello JJ !

JJ <jaej...@googlemail.com> wrote:

>> So you can exactly see how variables will be expanded.
>> I suggest you to try Ctrl-X (I don't rememeber if it exists in 4NT).
>>
>> You may want to upgrade to TakeCommand/TCC (must pay) or to TCC_LE
>> (free but some functions are disabled).

> I rarely use that shortcut. Thanks for the reminder.

I'm not sure I understand what your problem was, but may be your question is:

How can I suppress the normal meaning of special characters such as ?*/\|"`><&

Answer: using the escape character before the special character disables its meaning and copys it as is to the command line.
The escape character depends on the version of 4NT you are using, on what's in .INI file, on SETDOS /E usage.

In my .INI file, I have:
CommandSep=&
EscapeChar=^
So, if I'd like to have "%" on the command line as is, I just have to write "^%" and the "^" will be stripped while the "%" will be written as is.

Klaus Meinhard

unread,
Jun 3, 2012, 4:30:43 AM6/3/12
to
Hey JJ,

> The /X-3 works well.
> C:\4NT\4NT.EXE /U /C SETDOS/X-3 & C:\PROG.EXE $file$ & PAUSE

Don't forget to turn it back on :-) From the help file:

For example, to disable all features except alias expansion while you
are processing a text file containing special characters:

setdos /x-35678
... [perform text processing here]
setdos /x0

A SETLOCAL command will save the current SETDOS /X values for ENDLOCAL
to restore.

> I already have /X-4 as my default setting, but it doesn't seem to
> apply to double-quoted text.

Nested variable expansion. Why would you have it as default? All these
switches are meant to be turned off only if really needed.

> I also need file name processing for other programs. e.g.:
> "C:\Really &Difficult %Folder" becomes "C:\Really &Difficult
> %Folder\*"
> Simple append like "C:\Really &Difficult %Folder"\* would not be a
> valid Windows file specifier.

I don't know if I get this right - you want to append a backslash and
an asterisk to a directory name, meaning all files in that dir? Just
add them inside the double quotes.

> I guess I'll just have to make my own program for this.

It might get bulky for a command line. But asmall batch or alias
should do the trick.


--
herzliche Grüße,

Klaus Meinhard


JJ

unread,
Jun 3, 2012, 4:33:51 PM6/3/12
to
On Sun, 3 Jun 2012 10:30:43 +0200, "Klaus Meinhard" <K_Mei...@gmx.de> wrote:
>Don't forget to turn it back on :-) From the help file:
>
>For example, to disable all features except alias expansion while you
>are processing a text file containing special characters:
>
> setdos /x-35678
> ... [perform text processing here]
> setdos /x0
>
>A SETLOCAL command will save the current SETDOS /X values for ENDLOCAL
>to restore.

No. I don't need to since 4NT (the wrapper) would be terminated when PROG.EXE terminates and SETDOS
doesn't affect my other 4NT instances.

>Nested variable expansion. Why would you have it as default? All these
>switches are meant to be turned off only if really needed.

It messes with my old batch files.

>I don't know if I get this right - you want to append a backslash and
>an asterisk to a directory name, meaning all files in that dir? Just
>add them inside the double quotes.

Yes, when the file name is a subdirectory.
Adding it is the problem because some file names contains "&", "%", single-quote, and double-quote.
The file name is generated by PROG2.EXE via "$file$" macro, so it's fixed prior passing it to 4NT
command line.
Variable function (i.e.: %@UNQUOTE) would not work due to SETDOS /X-3.
And SETDOS /X-3 is needed to prevent 4NT from trying to expand variable in the file name.

>It might get bulky for a command line. But asmall batch or alias
>should do the trick.

That is, if I could solve this problem.

Laurent Jumet

unread,
Jun 3, 2012, 6:05:01 PM6/3/12
to

Hello JJ !

JJ <jaej...@googlemail.com> wrote:

> Adding it is the problem because some file names contains "&", "%",
> single-quote, and double-quote. The file name is generated by PROG2.EXE via
> "$file$" macro, so it's fixed prior passing it to 4NT command line. Variable
> function (i.e.: %@UNQUOTE) would not work due to SETDOS /X-3. And SETDOS
> /X-3 is needed to prevent 4NT from trying to expand variable in the file
> name.

I think I understand: you want to strip some characters from the filename.
Does @STRIP[chars,string] exist in 4NT? (I'm using TCC 11.0).

You could invoque not directly the filename generated by your PROG2.EXE, but something like this (try it at the command line):

echo %@STRIP[&%,this%is&thefilename]

(Caution: place the "%" ad the end otherwise it's the Esc char)

Klaus Meinhard

unread,
Jun 4, 2012, 2:28:10 AM6/4/12
to
Hallo JJ

> Yes, when the file name is a subdirectory.
> Adding it is the problem because some file names contains "&", "%",
> single-quote, and double-quote.
> The file name is generated by PROG2.EXE via "$file$" macro, so it's
> fixed prior passing it to 4NT
> command line.

So don't pass it to the command line. Pass it to a batch instead,
where you can inspect the name, manipulate it at will and then pass it
it on.
0 new messages