Using backticks in a batch file

#1
I'd like to call a program "prg" in a batch file "batch" with the following ("non-functional") command line:

[prg `%1`]

Sample action:

[batch `a b c`] should result in [prg `a b c`] being called.

How would I accomplish this?

nickles
 
#3
On Tue, 31 Aug 2010 05:42:42 -0400, nickles <>
wrote:

|[batch `a b c`] should result in [prg `a b c`] being called.
|
|How would I accomplish this?

Sorry, I didn't quite address the question in my first response.

This should work:

batch `^^ka b c^^k`

Warning: if prg is an exe and it processes it's args normally it will
see

argv[0] = prg
argv[1] = `a
argv[2] = b
argv[3] = c`
 
#4
@Vince

Thanks so far.

But how about these:
[batch `<h[1-3]>.*"File"`] (problem with redirection symbols),
[batch `"h[1-3].*"File"`] (please note that extra '^' at the end of the output).

The basic question is "Is there any reliaby quoting mechanism in tcc?"

Axel
 
#5
On Tue, 31 Aug 2010 10:23:52 -0400, nickles <>
wrote:

|@Vince
|
|Thanks so far.
|
|But how about these:
| [batch `<h[1-3]>.*"File"`] (problem with redirection symbols),
| [batch `"h[1-3].*"File"`] (please note that extra '^' at the end of the *output*).
|
|The basic question is "Is there any reliaby quoting mechanism in tcc?"

What output? I'm not sure what you want to do this time. TCC quoting
is reliable, but if you want to do something as odd as pass `quoted`
strings and redirection symbols to an external, it'll take experiment
and/or a good understanding of TCC's parsing, and it's likely to be
complicated.

Above, what do you want prg to get?
 
#6
On Tue, 31 Aug 2010 10:46:08 -0400, vefatica <>
wrote:

|TCC quoting
|is reliable, but if you want to do something as odd as pass `quoted`
|strings and redirection symbols to an external, it'll take experiment
|and/or a good understanding of TCC's parsing, and it's likely to be
|complicated.

I wrote a little exe, MYCMDLINE.EXE, to help you and others see what's
happening. Get ftp://lucky.syr.edu/mycmdline.exe.

All it does is output the command line with which it was called.

WCHAR *p = GetCommandLine();
size_t l = lstrlen(p);
DWORD dwWritten;
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), p, l, &dwWritten, NULL);

For example,

Code:
v:\> mycmdline `^k<>^k`
mycmdline `<>`
 
#7
Thanks Vince,

but (yeah, there is always a "but" ;-) how - from your experience - would I quote the first string I mentioned (obviously vBulletin ate the angle brackets) [batch `&lt;h[1-3]&gt;<h[1-3]>.*"File"`<h[1-3]>]<h[1-3]> reliably?

nickles</h[1-3]></h[1-3]></h[1-3]>
 
#8
On Tue, 31 Aug 2010 11:17:34 -0400, nickles <>
wrote:

|Thanks Vince,
|
|but (yeah, there is always a "but" ;-) how - from your experience would - I quote the first string I mentioned (obviously vBulletin ate the angle brackets) [batch `<h[1-3]><h[1-3]>.*"File"`<h[1-3]>]<h[1-3]> reliably?
|
|nickles</h[1-3]></h[1-3]></h[1-3]>

Code:
v:\> type echoargs.bat

u:\mycmdline.exe %1


v:\> echoargs.bat `^^k^^<h[1-3]^^>^^<h[1-3]^^>.*"File"^^k`

u:\mycmdline.exe `<h[1-3]><h[1-3]>.*"File"`
To protect the redirection symbols you must either "" them (""s won't
be removed) or escape them.

Above, the outer `` are removed immediately and one level of escaping
is removed as you enter the batch file, so

Code:
%1 is ^k^<h[1-3]^>^<h[1-3]^>.*"File"^k
When the mycmdline command is processed, another level of escaping is
removed, so mycmdline.exe gets

Code:
%1 is `<h[1-3]><h[1-3]>.*"File"`
After many years of using 4NT/TCC, I can't do these things without
experimentation.
 
#9
Hi Vince,

thanks for your continuing efforts and your help!

I've - experimenting and RTFM-wise - meanwhile found a solution to my problem:

Assuming the command:

Code:
batch `&lt;h[1-3].*"""File"""`
I use the following sequence of commands in batch.btm to be "successful":

Code:
setdos /x-567
set srch_str=`%1`
setdos /x0
prg %srch_str%
Thanks again

nickles