Page 1 of 2 12>
Topic Options
#154235 - 2005-12-29 07:33 PM small problem
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Anyone bored and looking for a challenge. Trying to get the DOS echo command to read in something this:

ECHO "^%PROGRAMFILE^%\MY APP"

and actually echo back this:

"%PROGRAMFILES%\MY APP"

The point is that I'm trying to pass a single parm to a util containing a long file name (hence the quotes) and that contains an env var that I DONT WANT TRANSLATED ... just using echo to test permutation ... anybody ?

Top
#154236 - 2005-12-29 08:21 PM Re: small problem
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
I think I understand your problem... as long as PROGRAMFILE is set to something the following should work...

ECHO "%%PROGRAMFILE%%\MY APP"

Top
#154237 - 2005-12-29 08:32 PM Re: small problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Assuming the missing S is just a typo and that you are not expecting DOS to create it magically, then Allen is not bang on.
Quote:

C:\Documents and Settings\LLigetfa>echo "%%ProgramFiles%%\my app"
"%C:\Program Files%\my app"

C:\Documents and Settings\LLigetfa>


_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#154238 - 2005-12-29 08:37 PM Re: small problem
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
{Edit; Les beat me too it...}

Also... if you are looking to use the environmental variable its PROGRAMFILES.

ECHO "^%PROGRAMFILES^%\MY APP"

On a side note, I could have sworn that if you echo a variable and it wasn't defined it would just display nothing, but when I am trying it right now on a XP SP2 box, its echoing whatever I type if the var is not defined... I must be getting this confused with something else.


Edited by Allen (2005-12-29 08:39 PM)

Top
#154239 - 2005-12-29 08:39 PM Re: small problem
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
echo ^"^%programfiles^%\my app^"

????

Top
#154240 - 2005-12-29 08:46 PM Re: small problem
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hmm hold the phone, this:

C:\>echo "^%PROGRAMFILES^%\MY APP"

gives this:

"^%PROGRAMFILES^%\MY APP"

i'm looking for the input string that will give this:

"%PROGRAMFILES%\MY APP"

Top
#154241 - 2005-12-29 08:46 PM Re: small problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
my bad
was testing from a live command window
if used in a batch file the following works:
echo "%%ProgramFiles%%\my app"
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#154242 - 2005-12-29 08:54 PM Re: small problem
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
And my suggestion?
Top
#154243 - 2005-12-29 08:57 PM Re: small problem
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
Your suggestion returns this from batch

Code:
"\my app"



And Les' returns this in batch


Code:
"%ProgramFiles%\my app"




Edited by NTDOC (2005-12-29 09:00 PM)

Top
#154244 - 2005-12-29 09:02 PM Re: small problem
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
interesting, from my command prompt

Quote:


C:\>echo ^"^%programfiles^%\my app^"
"%programfiles%\my app"




Top
#154245 - 2005-12-29 09:07 PM Re: small problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I got the same as maciep
Quote:

C:\>echo ^"^%ProgramFiles^%\my app"
"%ProgramFiles%\my app"

C:\>



Gave Shawn the same on MSN.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#154246 - 2005-12-29 09:08 PM Re: small problem
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
yup - that got it. funny thing is though - ECHO is a "special" proggy and not like many other command line utils ... ECHO echo's the double-quotes literally where-as other utils let the shell strip them off. trying to think of another util to prove this with though.
Top
#154247 - 2005-12-29 09:12 PM Re: small problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
ECHO treats what is between matched double quotes as special. That is why the first double quote is escaped unmatching them and makes that line work.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#154248 - 2005-12-29 09:18 PM Re: small problem
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Yeah but for most other proggies, to escape the quote, you use this:

> prog "\"kixtart\""

for example, see the last example of MS runas /?

Top
#154249 - 2005-12-29 09:22 PM Re: small problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
ROFL
You are like our typical noobs... the topic is about ECHO and % and it's not until the 14th reply that the truth be told that it really is about RUNAS!
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#154250 - 2005-12-29 09:24 PM Re: small problem
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
ok, based on all your suggestions, this seems to work:

runnas "\"^%programfiles^%\my app\""

I'm AM a noob with this funky command line stuff ;0)

Top
#154251 - 2005-12-29 09:28 PM Re: small problem
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I justed used ECHO because its the most handy utility for echo'ing out what the heck you typing to it. Wasn't until later i realized that ECHO treats its command line differently than most every other dos command. Hey - I just got flamed by Les - now I know what its like - it feels kinda good ;0)
Top
#154252 - 2005-12-29 09:30 PM Re: small problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
ROFLMAO
...like peeing your pants in a dark suit, it only feels good for a short while.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#154253 - 2005-12-29 11:09 PM Re: small problem
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
why dark?
I think it feels good for shorter while with white pants.

btw shawn, DOS commands and commandline win32 util are not really the same thing.
also, how the program inputs it's stdIN can differ.
_________________________
!

download KiXnet

Top
#154254 - 2005-12-29 11:35 PM Re: small problem
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Quote:


why dark?
I think it feels good for shorter while with white pants.
....





LOL
Maybe he speaks from experience?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 2 12>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 728 anonymous users online.
Newest Members
Audio, Hoschi, Comet, rrosell, PatrickPinto
17880 Registered Users

Generated in 0.075 seconds in which 0.026 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org