Discussion:
Problem passing parameter with "%" character
(too old to reply)
JJ
2012-06-01 22:12:24 UTC
Permalink
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
2012-06-01 23:59:50 UTC
Permalink
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
2012-06-02 00:57:21 UTC
Permalink
Post by E. S. Fabian
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.
Klaus Meinhard
2012-06-02 11:41:33 UTC
Permalink
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
2012-06-02 22:08:10 UTC
Permalink
Post by Klaus Meinhard
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.
Klaus Meinhard
2012-06-03 08:30:43 UTC
Permalink
Hey JJ,
Post by 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.
Post by JJ
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.
Post by JJ
"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.
Post by JJ
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
2012-06-03 20:33:51 UTC
Permalink
Post by Klaus Meinhard
For example, to disable all features except alias expansion while you
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.
Post by Klaus Meinhard
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.
Post by Klaus Meinhard
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.
Post by Klaus Meinhard
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
2012-06-03 22:05:01 UTC
Permalink
Hello JJ !
Post by JJ
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
/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)
--
Laurent Jumet - Point de Chat, Liège, BELGIUM
KeyID: 0xCFAF704C
[Restore address to laurent.jumet for e-mail reply.]
Klaus Meinhard
2012-06-04 06:28:10 UTC
Permalink
Hallo JJ
Post by 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.
--
Best regards,

* Klaus Meinhard *
<www.4dos.info>
Michael Bednarek
2012-06-02 06:20:34 UTC
Permalink
Post by JJ
Hello,
C:\PROG.EXE "C:\The File"
This command line is executed from another program (call it PROG2).
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)
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"
JJ
2012-06-02 22:10:22 UTC
Permalink
Post by Michael Bednarek
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.
Laurent Jumet
2012-06-02 06:47:01 UTC
Permalink
Hello JJ !
Post by JJ
C:\PROG.EXE "C:\The File"
This command line is executed from another program (call it PROG2).
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.]
JJ
2012-06-02 22:12:25 UTC
Permalink
Post by Laurent Jumet
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.
C:\PROG.EXE "C:\File %SystemRoot% %CLIENTNAME% Percent" & PAUSE
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
2012-06-02 22:17:21 UTC
Permalink
Post by Laurent Jumet
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.
C:\PROG.EXE "C:\File %SystemRoot% %CLIENTNAME% Percent" & PAUSE
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
2012-06-03 04:32:22 UTC
Permalink
Hello JJ !
Post by JJ
Post by Laurent Jumet
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.
--
Laurent Jumet - Point de Chat, Liège, BELGIUM
KeyID: 0xCFAF704C
[Restore address to laurent.jumet for e-mail reply.]
Loading...