Using backticks in a batch file

Jun 24, 2008
223
0
Siegen, Germany
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
 
May 20, 2008
11,520
102
Syracuse, NY, USA
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?

echo ^k%1^k
 
May 20, 2008
11,520
102
Syracuse, NY, USA
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`
 
Jun 24, 2008
223
0
Siegen, Germany
@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
 
May 20, 2008
11,520
102
Syracuse, NY, USA
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?
 
May 20, 2008
11,520
102
Syracuse, NY, USA
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 `<>`
 
Jun 24, 2008
223
0
Siegen, Germany
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]>
 
May 20, 2008
11,520
102
Syracuse, NY, USA
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.
 
Jun 24, 2008
223
0
Siegen, Germany
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
 
Similar threads
Thread starter Title Forum Replies Date
redwdc A comment on using shell folders Support 1
Jesse Heines Using Regular Expressions with the REN commanc Support 8
R WAD Unusable state when using Chinese characters Support 3
Joe Caverly Using TYPE with non-English text Support 22
L Using TCC.exe through an SSH connection Support 3
Joe Caverly Using @PSHELL from @EVAL Support 8
Jay Sage Command Will Not Run Using Short Name of Path Support 5
Jay Sage Cannot Postion Cursor in Command Line Using Mouse Support 7
MikeBaas Using the debugger Support 2
Joe Caverly Multiple Text Searches at once using FFIND or TPIPE Support 4
Dick Johnson Using the @instr function Support 5
Joe Caverly Using this CMD technique from TCC Support 17
Joe Caverly What version and Windows OS are you using? Support 3
Craig Fitzgerald Problems using tcstart.btm Support 3
R How to? Append files in multiple subfolders using copy? Support 8
M Ctrl-C when using command line history does nothing Support 2
Joe Caverly Using a Directory Alias with @iniwrite fails Support 14
C French accents using msgbox Support 4
C "Failed to update the system registry. Please try using REGEDIT" Support 3
x13 Problem listing repository files using DIR http(s)://... Support 8
R Regex using ^ Support 2
cxxl WAD Mouse movement sluggish when using TCC list Support 3
jfalch WAD internal "which" should check for FILEEXIST when using AppPaths entry Support 8
D How to? Scale font in TCC using wheel mouse or other means Support 2
fpefpe Documentation copy/move using /c or /u Support 2
gschizas Fixed Using codepage 65001 (UTF-8) breaks non-ASCII characters Support 8
D How to? Use typed envars using regex. Support 3
epement Using "everything" Support 10
U Installing the Compaq Visual Fortran 6.0 compiler using Take Command Support 8
Alexander WAD The number of files and dirs are multiplied when using multiple wildcards Support 6
T using bottom line for status bar Support 3
A How to? How do you launch TCC/LE using the already-open instance? Support 5
rps Fixed Using last argument variable ! Support 5
M Incorrect ARGV1 when using linux-style paths Support 4
D How to? Using a custom ini file with TCC from Take Command Support 7
thedave WAD Unable to type various characters using Windows 8's onscreen keyboard Support 7
D Documentation Using "send all input to other tabs" Support 11
Joe Caverly Word Count using TPIPE Support 10
Phileosophos Fixed Option Dialog Hangs when Using Help Support 7
MickeyF problem using COM object in VBScript from v16 x64 TCC but not from v15 32-bit TCC Support 4
S How to? How do I distinguish missing source file from download error when using HTTP? Support 6
Jay Sage Using EVERYTHING Command in TCMD15 Support 5
Charles Dye Odd behavior after using OPTION "Advanced" tab Support 2
T How to? Using FOLDERMONITOR 1 event causes multiple trigger(ing)s Support 8
samintz WAD FILEWRITE using SMOPEN Support 1
ehab aboudaya How to? 2 GUI questions and return HWND using TakeCommandIPC Support 3
R Fixed Using %~dp1 for paths with unavailable drives Support 6
C Using dif. sending addresses with sendmail Support 11
R TC 13 / Using TCDIALOG to exit commands Support 4
epement Video tutorials of using Take Command Support 2

Similar threads