Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account

# [BTACH] 'SET Va=St' with '& ECHO' doesn't work

21 replies to this topic

### #1 Outbreaker Posted 12 March 2015 - 07:23 AM

Outbreaker

• Member
• 323 posts
• Joined 08-August 07
• OS:Windows 7 x86
• Country:

HI,

I'm trying to get this first command line here to work but i have no luck to get it working.

@ECHO OFF
SET "FN=FolderName" & ECHO "%FN%"
PAUSE

﻿

But on separate lines i works.

@ECHO OFF
SET "FN=FolderName"
ECHO "%FN%"
PAUSE

Edited by Outbreaker, 12 March 2015 - 07:29 AM.

### #2 jaclaz Posted 12 March 2015 - 07:34 AM

jaclaz

The Finder

• Developer
• 15,185 posts
• Joined 23-July 04
• OS:none specified
• Country:

Try:

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SET "FN=FolderName" & ECHO "%FN%"
PAUSE

SET FN=
CALL SET "FN=FolderName" & FOR /F "Tokens=2 delims==" %%A IN ('SET FN') DO ECHO "%%A"
PAUSE

SET FN=
SETLOCAL ENABLEDELAYEDEXPANSION
SET "FN=FolderName" & ECHO "!FN!"
PAUSE

jaclaz

### #3 Outbreaker Posted 12 March 2015 - 08:09 AM

Outbreaker

• Member
• 323 posts
• Joined 08-August 07
• OS:Windows 7 x86
• Country:

The first example didn't work so i used the last one but since i need to have everything in one code line i used this code below this one should work but it doesn't.

CMD /Q /C V:ON SET "FM=FolderName" & ECHO "!FM!"

Edited by Outbreaker, 12 March 2015 - 08:48 AM.

### #4 jaclaz Posted 12 March 2015 - 09:30 AM

jaclaz

The Finder

• Developer
• 15,185 posts
• Joined 23-July 04
• OS:none specified
• Country:

The first example didn't work so i used the last one but since i need to have everything in one code line i used this code below this one should work but it doesn't.



CMD /Q /C V:ON SET "FM=FolderName" & ECHO "!FM!"

Well, you are in the (common BTW) issue of mis-communicating, the known xyz or the chocolate covered banana:

http://homepage.ntlw...red-banana.html

You want to reach a goal, but you do not specify it and ask a question related to a tiny bit of what you believe to be the way to reach that goal (which may or may not the "right" way)

However try:

CMD V:ON /Q /C "SET "FN=FolderName" &FOR /F "tokens=2 delims==" %%A IN ('SET FN') DO ECHO "%%A""

jaclaz

• Outbreaker likes this

### #5 Outbreaker Posted 12 March 2015 - 10:02 AM

Outbreaker

• Member
• 323 posts
• Joined 08-August 07
• OS:Windows 7 x86
• Country:

Thank you this command line is working great.

### #6 Yzöwl Posted 12 March 2015 - 03:17 PM

Yzöwl

Wise Owl

• Super Moderator
• 4,053 posts
• Joined 13-October 04
• OS:Windows 7 x64
• Country:

Donator

Am I missing something?

CMD /Q/D/C "SET "FN=FolderName"&CALL ECHO;"%FN%""

If you want to actually read the output then use either:

CMD /Q/D/K "SET "FN=FolderName"&CALL ECHO;"%FN%""

or:

CMD /Q/D/C "SET "FN=FolderName"&CALL ECHO;"%FN%"&PING -n 4 127.0.0.1>NUL"

### #7 jaclaz Posted 13 March 2015 - 04:34 AM

jaclaz

The Finder

• Developer
• 15,185 posts
• Joined 23-July 04
• OS:none specified
• Country:

Am I missing something?

Not yet.

Till now the usual screenplay has been followed to the letter:

2. jaclaz provides a possible solution
3. Yzöwl provides another (often better) one

at this point normally Gunsmokingman enters the scene and posts a .vbs to the same effect of the batches/snippets posted earlier, this time since the topic seems to be "strictly" batch, this might not happen that would be a twist to the story...

jaclaz

• Outbreaker likes this

### #8 Yzöwl Posted 13 March 2015 - 05:57 AM

Yzöwl

Wise Owl

• Super Moderator
• 4,053 posts
• Joined 13-October 04
• OS:Windows 7 x64
• Country:

Donator

Strangely, I think I really am missing something!

...the point!

Why set a variable for a fraction of a second, the sole purpose of which is to output its value to a console which would have closed before reading it?

### #9 jaclaz Posted 13 March 2015 - 07:24 AM

jaclaz

The Finder

• Developer
• 15,185 posts
• Joined 23-July 04
• OS:none specified
• Country:

You are not missing it , it simply does not exist , the whole point of the game, when played outside common rules, is to continuously shift the actual question towards something else at each iteration.

Technically this is often referred to as "Ninja Point" :

Spoiler

The original question made some sense, but as soon as a "normal" solution (actually two) were proposed, the question became different (having no actual practical use) and I suspect that even the modified question has very little in common with the actual goal/expected result/intended use, hence the reference to the xyz issue.

jaclaz

### #10 MHz Posted 13 March 2015 - 09:16 PM

MHz

Just simple

• Member
• 1,666 posts
• Joined 02-August 04
• OS:Windows 7 x64
• Country:

The first example didn't work so i used the last one but since i need to have everything in one code line i used this code below this one should work but it doesn't.

CMD /Q /C V:ON SET "FM=FolderName" & ECHO "!FM!"

Something to learn from this example.

The command string should follow /C or /K. Not using /C or /K immediately before the command string can expect failure.

V:ON would be an invalid parameter as a leading forward slash would be expected. CMD seems to ignore V:ON and thus delayed expansion is not turned on.

The command string has more then 2 double quotes. CMD may strip outer double quotes which may leave the command string as invalid. I would add extra outer double quotes on the command string and use the /S parameter to force CMD to strip those outer double quotes to be safe.

This information can be viewed by using the command CMD /? .

Following the information I mentioned above, I would use

CMD /S /Q /V:ON /C "SET "FM=FolderName" & ECHO "!FM!""


which tests as working.

Edited by MHz, 13 March 2015 - 09:20 PM.

• Outbreaker likes this

### #11 Outbreaker Posted 13 March 2015 - 10:27 PM

Outbreaker

• Member
• 323 posts
• Joined 08-August 07
• OS:Windows 7 x86
• Country:

Interesting this one works great thanks.

For anyone who asks themselves why i need this command here is the complete command i use.

CMD /S /Q /V:ON /C "SET "EmptyFolder=%ProgramFiles%\Software\temp" & PUSHD "!EmptyFolder!" && (RMDIR "!EmptyFolder!" /S /Q 2>NUL & POPD)"

This will delete everything in a folder but will not delete the Root folder (temp).

I'm only not sure if i should use the /S at the beginning or not it works with both.

Edited by Outbreaker, 13 March 2015 - 10:50 PM.

### #12 MHz Posted 14 March 2015 - 12:54 AM

MHz

Just simple

• Member
• 1,666 posts
• Joined 02-August 04
• OS:Windows 7 x64
• Country:
...

I'm only not sure if i should use the /S at the beginning or not it works with both.

Not needed in your case as the command string does not start with a double quote and end with a double quote. I saw all the double quotes and considered mentioning the /S yet after I posted I noticed that the command string begins with the command Set with double quotes coming later in the string.

If you do have a command string starting and ending with double quotes like (omitting the CMD /Q /C stuff being shown, rather just the command string)

"path\to\file.exe" > "path\to\logfile.log"


then CMD may strip the outer double quotes following legacy conditions. So it would be executed as

path\to\file.exe" > "path\to\logfile.log


which would fail as the redirection character is now double quoted with the white space.

Apologies for any confusion. You can still use the /S and use extra double quotes if you want though it is not needed with your command line shown.

• Outbreaker likes this

### #13 Yzöwl Posted 14 March 2015 - 02:22 AM

Yzöwl

Wise Owl

• Super Moderator
• 4,053 posts
• Joined 13-October 04
• OS:Windows 7 x64
• Country:

Donator

Interesting this one works great thanks.

For anyone who asks themselves why i need this command here is the complete command i use.

CMD /S /Q /V:ON /C "SET "EmptyFolder=%ProgramFiles%\Software\temp" & PUSHD "!EmptyFolder!" && (RMDIR "!EmptyFolder!" /S /Q 2>NUL & POPD)"

...but you're setting a variable for no reason

Without changing your code at all and just removing the pointless set you've shortned the command line!

CMD /S /Q /V:ON /C "PUSHD "%ProgramFiles%\Software\temp" && (RMDIR "%ProgramFiles%\Software\temp" /S /Q 2>NUL & POPD)"

...now you could even ignore the /s and /v switches and shorten it further.

### #14 jaclaz Posted 14 March 2015 - 06:15 AM

jaclaz

The Finder

• Developer
• 15,185 posts
• Joined 23-July 04
• OS:none specified
• Country:

I am still failing to see the actual practical use of this command, I mean is it to be included in a batch file or - as it seems - it is intended to be typed on the command line?

jaclaz

### #15 Outbreaker Posted 14 March 2015 - 06:44 AM

Outbreaker

• Member
• 323 posts
• Joined 08-August 07
• OS:Windows 7 x86
• Country:

I use this command in a .inf file.

11,,cmd.exe,,,"/Q /V:ON /C ""SET ""EmptyFolder=%ProgramFiles%\Software\temp"" & PUSHD ""!EmptyFolder!"" && (RMDIR ""!EmptyFolder!"" /S /Q 2>NUL & POPD)"""

Edited by Outbreaker, 14 March 2015 - 06:52 AM.

### #16 jaclaz Posted 14 March 2015 - 07:13 AM

jaclaz

The Finder

• Developer
• 15,185 posts
• Joined 23-July 04
• OS:none specified
• Country:

So - as expected  - you don't really need to set the variable at all and additionally you have no particular limitation in the complexity or length of the command string.

jaclaz

### #17 Outbreaker Posted 14 March 2015 - 07:47 AM

Outbreaker

• Member
• 323 posts
• Joined 08-August 07
• OS:Windows 7 x86
• Country:

I'm using this command multiple times and it makes it easier to edit and to find typos and i will also using this code in a different scenario.

Edited by Outbreaker, 14 March 2015 - 08:11 AM.

### #18 Yzöwl Posted 14 March 2015 - 09:30 AM

Yzöwl

Wise Owl

• Super Moderator
• 4,053 posts
• Joined 13-October 04
• OS:Windows 7 x64
• Country:

Donator

Surely that's what the [Strings] section is designed to do!

[Strings]
EmptyFolder = "PathTo\MyDir"

Then you may be able to just do this!

PUSHD %EmptyFolder%&&RD/S/Q %EmptyFolder%

### #19 jaclaz Posted 14 March 2015 - 09:54 AM

jaclaz

The Finder

• Developer
• 15,185 posts
• Joined 23-July 04
• OS:none specified
• Country:

Then you may be able to just do this!

.. and thus here goes yet another demonstration of the futility of falling in the xyz issue, if Outbreaker had since the beginning explained what his ACTUAL GOAL was and provided the needed context information, not only he would have had a valid solution faster, but it would have been better and simpler.

jaclaz

### #20 bphlpt Posted 14 March 2015 - 01:44 PM

bphlpt

• Member
• 1,915 posts
• Joined 12-May 07
• OS:none specified
• Country:

Well, you are in the (common BTW) issue of mis-communicating, the known xyz or the chocolate covered banana:
http://homepage.ntlw...red-banana.html

You want to reach a goal, but you do not specify it and ask a question related to a tiny bit of what you believe to be the way to reach that goal (which may or may not the "right" way)

...

Am I missing something?

...

Not yet.

Till now the usual screenplay has been followed to the letter:

• jaclaz provides a possible solution
• Yzöwl provides another (often better) one
at this point normally Gunsmokingman enters the scene and posts a .vbs to the same effect of the batches/snippets posted earlier,

...

Strangely, I think I really am missing something!

...the point!

...

You are not missing it , it simply does not exist , the whole point of the game, when played outside common rules, is to continuously shift the actual question towards something else at each iteration.

The original question made some sense, but as soon as a "normal" solution (actually two) were proposed, the question became different (having no actual practical use) and I suspect that even the modified question has very little in common with the actual goal/expected result/intended use, hence the reference to the xyz issue.

...

...but you're setting a variable for no reason

...

I am still failing to see the actual practical use of this command, I mean is it to be included in a batch file or - as it seems - it is intended to be typed on the command line?

...

So - as expected - you don't really need to set the variable at all and additionally you have no particular limitation in the complexity or length of the command string.

...

Then you may be able to just do this!

...

.. and thus here goes yet another demonstration of the futility of falling in the xyz issue, if Outbreaker had since the beginning explained what his ACTUAL GOAL was and provided the needed context information, not only he would have had a valid solution faster, but it would have been better and simpler.

LOL GSM and I have had similar "adventures" with Outbreaker, with similar results. Unfortunately, this thread was indeed as expected.

Cheers and Regards

### #21 Redhatcc Posted 15 March 2015 - 04:21 PM

Redhatcc

• Patrons
• 335 posts
• Joined 27-February 08
• OS:none specified
• Country:

Throwing this in the mix. Put the echo first then set.

@echo off
echo|set /p"FN=FolderName"
Pause


Citrix Engineer - AFCENT

### #22 Yzöwl Posted 15 March 2015 - 05:13 PM

Yzöwl

Wise Owl

• Super Moderator
• 4,053 posts
• Joined 13-October 04
• OS:Windows 7 x64
• Country:

Donator

Throwing this in the mix. Put the echo first then set.

@echo off
echo|set /p"FN=FolderName"
Pause

…unfortunately however, the actual task did not involve outputting anything at all to the screen!

Oh and also Outbreaker, since you are invoking the commands from an inf, there should also be no reason why you need to join all of the commands into a single line.

11,,cmd.exe,,,"/Q/C ""FOR /F ""DELIMS="" %A IN ('DIR/B/AD ""%ProgramFiles%\Software\temp\""') DO RD/S/Q ""%A"""
11,,cmd.exe,,,"/Q/C ""DEL/F/Q/A ""%ProgramFiles%\Software\temp\*.*"""

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users